Key generation in Java

Jason A. Donenfeld Jason at zx2c4.com
Tue Sep 26 00:16:33 CEST 2017


Fun school project!

Step 1:
Copy and paste this file into your java project:
https://raw.githubusercontent.com/rweather/noise-java/master/NoiseJava/src/com/southernstorm/noise/crypto/Curve25519.java

Step 2:
wg genkey is:

       import java.security.SecureRandom;
       ...
       SecureRandom random = new SecureRandom();
       byte privateKey[] = new byte[32];
       random.nextBytes(privateKey);
       privateKey[0]  &= 248;
       privateKey[31] &= 127;
       privateKey[31] |= 64;

Step 3:
wg pubkey is:

       byte publicKey[] = new byte[32];
       Curve25519.eval(publicKey, 0, privateKey, null);

Step 4:
Convert privateKey and publicKey to/from base64.


More information about the WireGuard mailing list