Package org.opensaml.security.crypto.ec
Class ECSupport
- java.lang.Object
-
- org.opensaml.security.crypto.ec.ECSupport
-
public final class ECSupport extends Object
Cryptography support related to Elliptic Curve.
-
-
Field Summary
Fields Modifier and Type Field Description private static org.slf4j.LoggerLOGLogger.
-
Constructor Summary
Constructors Modifier Constructor Description privateECSupport()Constructor.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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>getCurvesFromBouncyCastle()Return a set of all curves known to Bouncy Castle as instances ofNamedCurve.static NamedCurveRegistrygetGlobalNamedCurveRegistry()Get 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 ECParameterSpecgetParameterSpecForURI(String uri)Get 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.
-
-
-
Method Detail
-
performKeyAgreement
@Nonnull public static byte[] performKeyAgreement(@Nonnull ECPublicKey publicKey, @Nonnull ECPrivateKey privateKey, @Nullable String provider) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyExceptionPerform 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
@Nullable public static NamedCurveRegistry getGlobalNamedCurveRegistry()
Get the globalNamedCurveRegistryinstance.- Returns:
- the global named curve registry, or null if nothing registered
-
getNamedCurve
@Nullable public static NamedCurve getNamedCurve(@Nonnull ECPublicKey publicKey)
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
@Nullable public static NamedCurve getNamedCurve(@Nonnull String uri)
Get theNamedCurvefor the specified URI.- Parameters:
uri- the URI- Returns:
- the
NamedCurveinstance, or null if can not be determined,
-
getNamedCurveURI
@Nullable public static String getNamedCurveURI(@Nonnull ECPublicKey publicKey)
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
@Nullable public static ECParameterSpec getParameterSpecForURI(@Nonnull String uri)
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
@Nonnull @NonnullElements @NotLive public static Set<NamedCurve> getCurvesFromBouncyCastle()
Return a set of all curves known to Bouncy Castle as instances ofNamedCurve.- Returns:
- the set of curves known to Bouncy Castle
-
-