Class EcKey
- java.lang.Object
-
- com.microsoft.azure.keyvault.cryptography.EcKey
-
- All Implemented Interfaces:
IKey,Closeable,AutoCloseable
public class EcKey extends Object implements IKey
-
-
Field Summary
Fields Modifier and Type Field Description static Map<JsonWebKeyCurveName,String>CURVE_TO_SIGNATUREstatic Map<JsonWebKeyCurveName,String>CURVE_TO_SPEC_NAMEprotected StringdefaultEncryptionAlgorithmstatic StringP256static StringP256Kstatic StringP384static StringP521protected StringsignatureAlgorithm
-
Constructor Summary
Constructors Constructor Description EcKey()Constructor.EcKey(String kid)Constructor.EcKey(String kid, JsonWebKeyCurveName curve)Constructor.EcKey(String kid, JsonWebKeyCurveName curve, Provider provider)Constructor.EcKey(String kid, KeyPair keyPair)Constructor.EcKey(String kid, KeyPair keyPair, Provider provider)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()com.google.common.util.concurrent.ListenableFuture<byte[]>decryptAsync(byte[] ciphertext, byte[] iv, byte[] authenticationData, byte[] authenticationTag, String algorithm)com.google.common.util.concurrent.ListenableFuture<org.apache.commons.lang3.tuple.Triple<byte[],byte[],String>>encryptAsync(byte[] plaintext, byte[] iv, byte[] authenticationData, String algorithm)static EcKeyfromJsonWebKey(JsonWebKey jwk)Converts JSON web key to EC key pair, does not include the private key.static EcKeyfromJsonWebKey(JsonWebKey jwk, boolean includePrivateParameters)Converts JSON web key to EC key pair and include the private key if set to true.static EcKeyfromJsonWebKey(JsonWebKey jwk, boolean includePrivateParameters, Provider provider)Converts JSON web key to EC key pair and include the private key if set to true.JsonWebKeyCurveNamegetCurve()static JsonWebKeyCurveNamegetDefaultCurve()StringgetDefaultEncryptionAlgorithm()StringgetDefaultKeyWrapAlgorithm()StringgetDefaultSignatureAlgorithm()KeyPairgetKeyPair()StringgetKid()com.google.common.util.concurrent.ListenableFuture<org.apache.commons.lang3.tuple.Pair<byte[],String>>signAsync(byte[] digest, String algorithm)JsonWebKeytoJsonWebKey()Converts EcKey to JSON web key.com.google.common.util.concurrent.ListenableFuture<byte[]>unwrapKeyAsync(byte[] encryptedKey, String algorithm)com.google.common.util.concurrent.ListenableFuture<Boolean>verifyAsync(byte[] digest, byte[] signature, String algorithm)com.google.common.util.concurrent.ListenableFuture<org.apache.commons.lang3.tuple.Pair<byte[],String>>wrapKeyAsync(byte[] key, String algorithm)
-
-
-
Field Detail
-
P256
public static final String P256
- See Also:
- Constant Field Values
-
P384
public static final String P384
- See Also:
- Constant Field Values
-
P521
public static final String P521
- See Also:
- Constant Field Values
-
P256K
public static final String P256K
- See Also:
- Constant Field Values
-
CURVE_TO_SIGNATURE
public static final Map<JsonWebKeyCurveName,String> CURVE_TO_SIGNATURE
-
CURVE_TO_SPEC_NAME
public static final Map<JsonWebKeyCurveName,String> CURVE_TO_SPEC_NAME
-
signatureAlgorithm
protected final String signatureAlgorithm
-
defaultEncryptionAlgorithm
protected String defaultEncryptionAlgorithm
-
-
Constructor Detail
-
EcKey
public EcKey() throws NoSuchAlgorithmException, InvalidAlgorithmParameterExceptionConstructor. Generates a new EcKey with a P_256 curve and a randomly generated kid.
-
EcKey
public EcKey(String kid) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException
Constructor. Generates a new EcKey with a P_256 curve and the given kid.- Parameters:
kid-- Throws:
NoSuchAlgorithmExceptionInvalidAlgorithmParameterException
-
EcKey
public EcKey(String kid, JsonWebKeyCurveName curve) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException
Constructor. Generates a new EcKey with the given curve and kid.- Parameters:
kid-curve-- Throws:
NoSuchAlgorithmExceptionInvalidAlgorithmParameterException
-
EcKey
public EcKey(String kid, JsonWebKeyCurveName curve, Provider provider) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException
Constructor. Generates a new EcKey with the given curve and kid.- Parameters:
kid-curve-provider- Java security provider- Throws:
InvalidAlgorithmParameterExceptionNoSuchAlgorithmException
-
EcKey
public EcKey(String kid, KeyPair keyPair) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException
Constructor. Generates a new EcKey with the given keyPair. The keyPair must be an ECKey.- Parameters:
kid-keyPair-- Throws:
NoSuchAlgorithmExceptionInvalidAlgorithmParameterException
-
EcKey
public EcKey(String kid, KeyPair keyPair, Provider provider) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException
Constructor. Generates a new EcKey with the given keyPair. The keyPair must be an ECKey.- Parameters:
kid-keyPair-provider- Java security provider- Throws:
NoSuchAlgorithmExceptionInvalidAlgorithmParameterException
-
-
Method Detail
-
getDefaultCurve
public static JsonWebKeyCurveName getDefaultCurve()
-
fromJsonWebKey
public static EcKey fromJsonWebKey(JsonWebKey jwk) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeySpecException, NoSuchProviderException
Converts JSON web key to EC key pair, does not include the private key.- Parameters:
jwk-- Returns:
- EcKey
- Throws:
NoSuchAlgorithmExceptionInvalidAlgorithmParameterExceptionInvalidKeySpecExceptionNoSuchProviderException
-
fromJsonWebKey
public static EcKey fromJsonWebKey(JsonWebKey jwk, boolean includePrivateParameters) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeySpecException, NoSuchProviderException
Converts JSON web key to EC key pair and include the private key if set to true.- Parameters:
jwk-includePrivateParameters- true if the EC key pair should include the private key. False otherwise.- Returns:
- EcKey
- Throws:
NoSuchAlgorithmExceptionInvalidAlgorithmParameterExceptionInvalidKeySpecExceptionNoSuchProviderException
-
fromJsonWebKey
public static EcKey fromJsonWebKey(JsonWebKey jwk, boolean includePrivateParameters, Provider provider)
Converts JSON web key to EC key pair and include the private key if set to true.- Parameters:
jwk-includePrivateParameters- true if the EC key pair should include the private key. False otherwise.provider- the Java Security Provider- Returns:
- EcKey
-
toJsonWebKey
public JsonWebKey toJsonWebKey()
Converts EcKey to JSON web key.- Returns:
-
getCurve
public JsonWebKeyCurveName getCurve()
- Returns:
- curve of the key
-
getKeyPair
public KeyPair getKeyPair()
- Returns:
- the underlying keyPair of the key
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getDefaultEncryptionAlgorithm
public String getDefaultEncryptionAlgorithm()
- Specified by:
getDefaultEncryptionAlgorithmin interfaceIKey
-
getDefaultKeyWrapAlgorithm
public String getDefaultKeyWrapAlgorithm()
- Specified by:
getDefaultKeyWrapAlgorithmin interfaceIKey
-
getDefaultSignatureAlgorithm
public String getDefaultSignatureAlgorithm()
- Specified by:
getDefaultSignatureAlgorithmin interfaceIKey
-
decryptAsync
public com.google.common.util.concurrent.ListenableFuture<byte[]> decryptAsync(byte[] ciphertext, byte[] iv, byte[] authenticationData, byte[] authenticationTag, String algorithm) throws NoSuchAlgorithmException- Specified by:
decryptAsyncin interfaceIKey- Throws:
NoSuchAlgorithmException
-
encryptAsync
public com.google.common.util.concurrent.ListenableFuture<org.apache.commons.lang3.tuple.Triple<byte[],byte[],String>> encryptAsync(byte[] plaintext, byte[] iv, byte[] authenticationData, String algorithm) throws NoSuchAlgorithmException
- Specified by:
encryptAsyncin interfaceIKey- Throws:
NoSuchAlgorithmException
-
wrapKeyAsync
public com.google.common.util.concurrent.ListenableFuture<org.apache.commons.lang3.tuple.Pair<byte[],String>> wrapKeyAsync(byte[] key, String algorithm) throws NoSuchAlgorithmException
- Specified by:
wrapKeyAsyncin interfaceIKey- Throws:
NoSuchAlgorithmException
-
unwrapKeyAsync
public com.google.common.util.concurrent.ListenableFuture<byte[]> unwrapKeyAsync(byte[] encryptedKey, String algorithm) throws NoSuchAlgorithmException- Specified by:
unwrapKeyAsyncin interfaceIKey- Throws:
NoSuchAlgorithmException
-
signAsync
public com.google.common.util.concurrent.ListenableFuture<org.apache.commons.lang3.tuple.Pair<byte[],String>> signAsync(byte[] digest, String algorithm) throws NoSuchAlgorithmException
- Specified by:
signAsyncin interfaceIKey- Throws:
NoSuchAlgorithmException
-
verifyAsync
public com.google.common.util.concurrent.ListenableFuture<Boolean> verifyAsync(byte[] digest, byte[] signature, String algorithm) throws NoSuchAlgorithmException
- Specified by:
verifyAsyncin interfaceIKey- Throws:
NoSuchAlgorithmException
-
-