Class Keys


  • public class Keys
    extends java.lang.Object
    Utility methods for generating XSalsa20Poly1305 keys.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] generatePrivateKey()
      generates a Curve25519 private key.
      static byte[] generatePublicKey​(byte[] privateKey)
      Generates a Curve25519 public key given a Curve25519 private key.
      static byte[] generateSecretKey()
      Generates a 32-byte secret key.
      static byte[] sharedSecret​(byte[] publicKey, byte[] privateKey)
      Calculate the X25519/HSalsa20 shared secret for the given public key and private key.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • generateSecretKey

        public static byte[] generateSecretKey()
        Generates a 32-byte secret key.
        Returns:
        a 32-byte secret key
      • generatePrivateKey

        public static byte[] generatePrivateKey()
        generates a Curve25519 private key.
        Returns:
        a Curve25519 private key
      • generatePublicKey

        public static byte[] generatePublicKey​(byte[] privateKey)
        Generates a Curve25519 public key given a Curve25519 private key.
        Parameters:
        privateKey - a Curve25519 private key
        Returns:
        the public key matching privateKey
      • sharedSecret

        public static byte[] sharedSecret​(byte[] publicKey,
                                          byte[] privateKey)
        Calculate the X25519/HSalsa20 shared secret for the given public key and private key.
        Parameters:
        publicKey - the recipient's public key
        privateKey - the sender's private key
        Returns:
        a 32-byte secret key only re-calculable by the sender and recipient