Class SymmetricKey
- java.lang.Object
-
- com.microsoft.azure.keyvault.cryptography.SymmetricKey
-
- All Implemented Interfaces:
IKey
,Closeable
,AutoCloseable
public class SymmetricKey extends Object implements IKey
A simple symmetric key implementation
-
-
Field Summary
Fields Modifier and Type Field Description static int
DefaultKeySize
static int
KeySize128
static int
KeySize192
static int
KeySize256
static int
KeySize384
static int
KeySize512
-
Constructor Summary
Constructors Constructor Description SymmetricKey()
Creates a SymmetricKey with a random key identifier and a random key with DefaultKeySize bits.SymmetricKey(String kid)
Creates a SymmetricKey with the specified key identifier and a random key with DefaultKeySize bits.SymmetricKey(String kid, byte[] keyBytes)
Creates a SymmetricKey with the specified key identifier and key material.SymmetricKey(String kid, byte[] keyBytes, Provider provider)
Creates a SymmetricKey with the specified key identifier and key material that uses the specified Provider.SymmetricKey(String kid, int keySizeInBytes)
Creates a SymmetricKey with the specified key identifier and a random key with the specified size.SymmetricKey(String kid, int keySizeInBytes, Provider provider)
Creates a SymmetricKey with the specified key identifier and a random key with the specified size that uses the specified provider.
-
Method Summary
All 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)
String
getDefaultEncryptionAlgorithm()
String
getDefaultKeyWrapAlgorithm()
String
getDefaultSignatureAlgorithm()
String
getKid()
com.google.common.util.concurrent.ListenableFuture<org.apache.commons.lang3.tuple.Pair<byte[],String>>
signAsync(byte[] digest, String algorithm)
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
-
KeySize128
public static final int KeySize128
- See Also:
- Constant Field Values
-
KeySize192
public static final int KeySize192
- See Also:
- Constant Field Values
-
KeySize256
public static final int KeySize256
- See Also:
- Constant Field Values
-
KeySize384
public static final int KeySize384
- See Also:
- Constant Field Values
-
KeySize512
public static final int KeySize512
- See Also:
- Constant Field Values
-
DefaultKeySize
public static final int DefaultKeySize
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SymmetricKey
public SymmetricKey()
Creates a SymmetricKey with a random key identifier and a random key with DefaultKeySize bits.
-
SymmetricKey
public SymmetricKey(String kid)
Creates a SymmetricKey with the specified key identifier and a random key with DefaultKeySize bits.- Parameters:
kid
- The key identifier to use.
-
SymmetricKey
public SymmetricKey(String kid, int keySizeInBytes)
Creates a SymmetricKey with the specified key identifier and a random key with the specified size.- Parameters:
kid
- The key identifier to use.keySizeInBytes
- The key size to use in bytes.
-
SymmetricKey
public SymmetricKey(String kid, int keySizeInBytes, Provider provider)
Creates a SymmetricKey with the specified key identifier and a random key with the specified size that uses the specified provider.- Parameters:
kid
- The key identifier to use.keySizeInBytes
- The key size to use in bytes.provider
- The provider to use (optional, null for default)
-
SymmetricKey
public SymmetricKey(String kid, byte[] keyBytes)
Creates a SymmetricKey with the specified key identifier and key material.- Parameters:
kid
- The key identifier to use.keyBytes
- The key material to use.
-
SymmetricKey
public SymmetricKey(String kid, byte[] keyBytes, Provider provider)
Creates a SymmetricKey with the specified key identifier and key material that uses the specified Provider.- Parameters:
kid
- The key identifier to use.keyBytes
- The key material to use.provider
- The Provider to use (optional, null for default)
-
-
Method Detail
-
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)
-
verifyAsync
public com.google.common.util.concurrent.ListenableFuture<Boolean> verifyAsync(byte[] digest, byte[] signature, String algorithm)
- Specified by:
verifyAsync
in interfaceIKey
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
-