Package com.yahoo.security
Class KeyUtils
java.lang.Object
com.yahoo.security.KeyUtils
- Author:
- bjorncs
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]ecdh(XECPrivateKey privateKey, XECPublicKey publicKey) Computes a shared secret using the Elliptic Curve Diffie-Hellman (ECDH) protocol for X25519 curves.static PublicKeyextractPublicKey(PrivateKey privateKey) static XECPublicKeyextractX25519PublicKey(XECPrivateKey privateKey) static XECPrivateKeyfromBase58EncodedX25519PrivateKey(String base58pk) static XECPublicKeyfromBase58EncodedX25519PublicKey(String base58pk) static XECPrivateKeyfromBase64EncodedX25519PrivateKey(String base64pk) static XECPublicKeyfromBase64EncodedX25519PublicKey(String base64pk) static PrivateKeystatic PublicKeystatic XECPrivateKeyfromRawX25519PrivateKey(byte[] rawScalarBytes) static XECPublicKeyfromRawX25519PublicKey(byte[] rawKeyBytes) static KeyPairgenerateKeypair(KeyAlgorithm algorithm) static KeyPairgenerateKeypair(KeyAlgorithm algorithm, int keySize) static KeyPairstatic KeyPairstatic StringtoBase58EncodedX25519PrivateKey(XECPrivateKey privateKey) static StringtoBase58EncodedX25519PublicKey(XECPublicKey publicKey) static StringtoBase64EncodedX25519PrivateKey(XECPrivateKey privateKey) static StringtoBase64EncodedX25519PublicKey(XECPublicKey publicKey) static KeyPairtoKeyPair(PrivateKey privateKey) static StringtoPem(PrivateKey privateKey) static StringtoPem(PrivateKey privateKey, KeyFormat format) static Stringstatic byte[]toRawX25519PrivateKeyBytes(XECPrivateKey privateKey) static byte[]toRawX25519PublicKeyBytes(XECPublicKey publicKey) Returns the bytes representing the BigInteger of the X25519 public key EC point U coordinate
-
Method Details
-
generateKeypair
-
generateKeypair
-
extractPublicKey
-
toKeyPair
-
keyPairFromPemEncodedPrivateKey
-
fromPemEncodedPrivateKey
-
fromPemEncodedPublicKey
-
toPem
-
toPem
-
toPem
-
fromRawX25519PublicKey
-
toRawX25519PublicKeyBytes
Returns the bytes representing the BigInteger of the X25519 public key EC point U coordinate -
fromBase64EncodedX25519PublicKey
-
toBase64EncodedX25519PublicKey
-
fromBase58EncodedX25519PublicKey
-
toBase58EncodedX25519PublicKey
-
fromRawX25519PrivateKey
-
toRawX25519PrivateKeyBytes
-
fromBase64EncodedX25519PrivateKey
-
toBase64EncodedX25519PrivateKey
-
fromBase58EncodedX25519PrivateKey
-
toBase58EncodedX25519PrivateKey
-
generateX25519KeyPair
-
extractX25519PublicKey
-
ecdh
Computes a shared secret using the Elliptic Curve Diffie-Hellman (ECDH) protocol for X25519 curves.Let Bob have private (secret) key
skBand public keypkB. Let Alice have private keyskAand public keypkA. ECDH lets both parties separately compute their own side of:ecdh(skB, pkA) == ecdh(skA, pkB)
This arrives at the same shared secret without needing to know the secret key of the other party, but both parties must know their own secret to derive the correct shared secret. Third party Eve sneaking around in the bushes cannot compute the shared secret without knowing at least one of the secrets.
Performs RFC 7748-recommended (and RFC 9180-mandated) check for "non-contributory" private keys by checking if the resulting shared secret comprises all zero bytes.
- Parameters:
privateKey- X25519 private keypublicKey- X25519 public key- Returns:
- shared Diffie-Hellman secret. Security note: this value should never be used directly as a key; use a key derivation function (KDF).
- See Also:
-