Curve25519 is an elliptic curve offering 128 bits of security and designed for use with the elliptic curve Diffie–Hellman (ECDH) key agreement scheme. It is one of the fastest ECC curves
repositories {
mavenCentral()
}
dependencies {
implementation 'com.github.netricecake:x25519:2.0'
}
<dependencies>
<dependency>
<groupId>com.github.netricecake</groupId>
<artifactId>x25519</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
Make private key :
Curve25519.generateRandomKey() //Return 32 byte random bytes
Make public key from private key :
Curve25519.publicKey(byte[] privateKey)
Get shared secret :
Curve25519.sharedSecrete(byte[] privateKey, byte[] publicKey) //Private key and Public key must be 32 byte array
Example :
byte[] aPrivate = Curve25519.generateRandomKey();
byte[] aPublic = Curve25519.publicKey(aPrivate);
byte[] bPrivate = Curve25519.generateRandomKey();
byte[] bPublic = Curve25519.publicKey(bPrivate);
byte[] aSharedSecret = Curve25519.sharedSecret(aPrivate, bPublic);
byte[] bSharedSecret = Curve25519.sharedSecret(bPrivate, aPublic);
Version 1.0 has one big problem. Please use version 2.0.