Package org.opensaml.security.crypto.ec
Class ECSupport
java.lang.Object
org.opensaml.security.crypto.ec.ECSupport
Cryptography support related to Elliptic Curve.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ECParameterSpecconvert(org.bouncycastle.jce.spec.ECNamedCurveParameterSpec bcSpec) Convert a Bouncy CastleECNamedCurveParameterSpec, such as obtained from theECNamedCurveTable, to a standard JCAECParameterSpec.static ECPointdecodeECPoint(byte[] data, EllipticCurve curve) Decode theECPointfrom the byte representation.static byte[]encodeECPointUncompressed(ECPoint point, EllipticCurve curve) Encode the uncompressed byte representation of the specifiedECPoint.static KeyPairgenerateCompatibleKeyPair(ECPublicKey publicKey, String provider) Generate a key pair whose parameters are compatible with those of the specified EC public key.static Set<NamedCurve>Return a set of all curves known to Bouncy Castle as instances ofNamedCurve.static NamedCurveRegistryGet the globalNamedCurveRegistryinstance.static NamedCurvegetNamedCurve(String uri) Get theNamedCurvefor the specified URI.static NamedCurvegetNamedCurve(ECPublicKey publicKey) Get theNamedCurvefor the specifiedECPublicKey.static StringgetNamedCurveURI(ECPublicKey publicKey) Get the URI of the named curve for the specifiedECPublicKey.static ECParameterSpecGet anECParameterSpecinstance which corresponds to the specified named curve URI.static byte[]performKeyAgreement(ECPublicKey publicKey, ECPrivateKey privateKey, String provider) Perform ECDH key agreement between the given public and private keys.private static byte[]trimZeroes(byte[] b) Trim leading zero bytes from the byte array.
-
Field Details
-
LOG
@Nonnull private static final org.slf4j.Logger LOGLogger.
-
-
Constructor Details
-
ECSupport
private ECSupport()Constructor.
-
-
Method Details
-
performKeyAgreement
@Nonnull public static byte[] performKeyAgreement(@Nonnull ECPublicKey publicKey, @Nonnull ECPrivateKey privateKey, @Nullable String provider) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException Perform ECDH key agreement between the given public and private keys.- Parameters:
publicKey- the public keyprivateKey- the private keyprovider- the optional security provider to use- Returns:
- the secret produced by key agreement
- Throws:
NoSuchAlgorithmException- if algorithm is unknownNoSuchProviderException- if provider is unknownInvalidKeyException- if supplied key is invalid
-
generateCompatibleKeyPair
@Nonnull public static KeyPair generateCompatibleKeyPair(@Nonnull ECPublicKey publicKey, @Nullable String provider) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException Generate a key pair whose parameters are compatible with those of the specified EC public key.- Parameters:
publicKey- the public keyprovider- the optional security provider to use- Returns:
- the generated key pair
- Throws:
NoSuchAlgorithmException- if algorithm is unknownNoSuchProviderException- if provider is unknownInvalidAlgorithmParameterException- if the public key'sECParameterSpecis not supported
-
getGlobalNamedCurveRegistry
Get the globalNamedCurveRegistryinstance.- Returns:
- the global named curve registry, or null if nothing registered
-
getNamedCurve
Get theNamedCurvefor the specifiedECPublicKey.- Parameters:
publicKey- theECPublicKey- Returns:
- the
NamedCurveinstance, or null if can not be determined, possibly because the key's domain parameters do not correspond to a named curve
-
getNamedCurve
Get theNamedCurvefor the specified URI.- Parameters:
uri- the URI- Returns:
- the
NamedCurveinstance, or null if can not be determined,
-
getNamedCurveURI
Get the URI of the named curve for the specifiedECPublicKey.- Parameters:
publicKey- theECPublicKey- Returns:
- the URI or null if can not be determined, possibly because is not a named curve
-
getParameterSpecForURI
Get anECParameterSpecinstance which corresponds to the specified named curve URI.- Parameters:
uri- the URI of the named curve- Returns:
- the
ECParameterSpecinstance
-
decodeECPoint
@Nonnull public static ECPoint decodeECPoint(@Nonnull byte[] data, @Nonnull EllipticCurve curve) throws KeyException Decode theECPointfrom the byte representation.Only uncompressed point types (0x04) are supported.
- Parameters:
data- the EC point byte representationcurve- theEllipticCurve- Returns:
- the
ECPoint - Throws:
KeyException- if point is not in uncompressed format, or point does not match curve's field size
-
encodeECPointUncompressed
@Nonnull public static byte[] encodeECPointUncompressed(@Nonnull ECPoint point, @Nonnull EllipticCurve curve) Encode the uncompressed byte representation of the specifiedECPoint.- Parameters:
point- theECPointcurve- theEllipticCurve- Returns:
- the uncompressed byte representation
-
trimZeroes
@Nonnull private static byte[] trimZeroes(@Nonnull byte[] b) Trim leading zero bytes from the byte array.- Parameters:
b- the byte array- Returns:
- the byte array without leading zero bytes
-
convert
@Nullable public static ECParameterSpec convert(@Nullable org.bouncycastle.jce.spec.ECNamedCurveParameterSpec bcSpec) Convert a Bouncy CastleECNamedCurveParameterSpec, such as obtained from theECNamedCurveTable, to a standard JCAECParameterSpec.- Parameters:
bcSpec- the Bouncy Castle parameter spec instance- Returns:
- the standard parameter spec instance
-
getCurvesFromBouncyCastle
Return a set of all curves known to Bouncy Castle as instances ofNamedCurve.- Returns:
- the set of curves known to Bouncy Castle
-