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_SIGNATURE
static Map<JsonWebKeyCurveName,String>
CURVE_TO_SPEC_NAME
protected String
defaultEncryptionAlgorithm
static String
P256
static String
P256K
static String
P384
static String
P521
protected String
signatureAlgorithm
-
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 void
close()
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 EcKey
fromJsonWebKey(JsonWebKey jwk)
Converts JSON web key to EC key pair, does not include the private key.static EcKey
fromJsonWebKey(JsonWebKey jwk, boolean includePrivateParameters)
Converts JSON web key to EC key pair and include the private key if set to true.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.JsonWebKeyCurveName
getCurve()
static JsonWebKeyCurveName
getDefaultCurve()
String
getDefaultEncryptionAlgorithm()
String
getDefaultKeyWrapAlgorithm()
String
getDefaultSignatureAlgorithm()
KeyPair
getKeyPair()
String
getKid()
com.google.common.util.concurrent.ListenableFuture<org.apache.commons.lang3.tuple.Pair<byte[],String>>
signAsync(byte[] digest, String algorithm)
JsonWebKey
toJsonWebKey()
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, InvalidAlgorithmParameterException
Constructor. 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:
NoSuchAlgorithmException
InvalidAlgorithmParameterException
-
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:
NoSuchAlgorithmException
InvalidAlgorithmParameterException
-
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:
InvalidAlgorithmParameterException
NoSuchAlgorithmException
-
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:
NoSuchAlgorithmException
InvalidAlgorithmParameterException
-
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:
NoSuchAlgorithmException
InvalidAlgorithmParameterException
-
-
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:
NoSuchAlgorithmException
InvalidAlgorithmParameterException
InvalidKeySpecException
NoSuchProviderException
-
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:
NoSuchAlgorithmException
InvalidAlgorithmParameterException
InvalidKeySpecException
NoSuchProviderException
-
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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
getDefaultEncryptionAlgorithm
public String getDefaultEncryptionAlgorithm()
- Specified by:
getDefaultEncryptionAlgorithm
in interfaceIKey
-
getDefaultKeyWrapAlgorithm
public String getDefaultKeyWrapAlgorithm()
- Specified by:
getDefaultKeyWrapAlgorithm
in interfaceIKey
-
getDefaultSignatureAlgorithm
public String getDefaultSignatureAlgorithm()
- Specified by:
getDefaultSignatureAlgorithm
in 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:
decryptAsync
in 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:
encryptAsync
in 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:
wrapKeyAsync
in interfaceIKey
- Throws:
NoSuchAlgorithmException
-
unwrapKeyAsync
public com.google.common.util.concurrent.ListenableFuture<byte[]> unwrapKeyAsync(byte[] encryptedKey, String algorithm) throws NoSuchAlgorithmException
- Specified by:
unwrapKeyAsync
in 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:
signAsync
in interfaceIKey
- Throws:
NoSuchAlgorithmException
-
verifyAsync
public com.google.common.util.concurrent.ListenableFuture<Boolean> verifyAsync(byte[] digest, byte[] signature, String algorithm) throws NoSuchAlgorithmException
- Specified by:
verifyAsync
in interfaceIKey
- Throws:
NoSuchAlgorithmException
-
-