Java EdDSA (Ed25519 / Ed448) Example

EdDSA (Edwards-Curve Digital Signature Algorithm) [RFC 8032] is another additional digital signature scheme added in Java 15 thorough JEP 339.

It does not replace the existing Elliptic Curve Digital Signature Algorithm (ECDSA) in JDK.

EdDSA provides following parameter choices :

Algorithm NameDescription
EdDSAEdwards-Curve signature algorithm as defined in RFC 8032
Ed25519Edwards-Curve signature algorithm with Ed25519 as defined in RFC 8032
Ed448Edwards-Curve signature algorithm with Ed448 as defined in RFC 8032

1. Advantages of EdDSA (using Ed25519)

  • Provides platform-independent implementation of EdDSA with better performance than the existing ECDSA implementation.
  • Does not change the execution time based on the length of secret key.
  • Provides standardized parameter sets such as Ed25519 and Ed448 which can be specified using identifiers.
  • It is scheduled to be integrated with JSSE for TLS 1.3. It is one of only three signature schemes that are allowed in TLS 1.3.

2. Java EdDSA Example

Given below is a code example of how to use the EdDSA algorithm in a Java program to encrypt a String.

import java.nio.charset.StandardCharsets;
import java.util.Base64;

public class EdwardAlgoExample {
  public static void main(String[] args)
      throws NoSuchAlgorithmException, InvalidKeyException, SignatureException {

    KeyPairGenerator kpg = KeyPairGenerator.getInstance("Ed25519");
    KeyPair kp = kpg.generateKeyPair();

    byte[] msg = "test_string".getBytes(StandardCharsets.UTF_8);

    Signature sig = Signature.getInstance("Ed25519");
    byte[] s = sig.sign();

    String encodedString = Base64.getEncoder().encodeToString(s);

Program output.


Happy Learning !!


Notify of
Most Voted
Newest Oldest
Inline Feedbacks
View all comments

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.