public class CryptographyAsyncClient extends Object
Samples to construct the sync client
CryptographyAsyncClient cryptographyAsyncClient = new CryptographyClientBuilder()
.keyIdentifier("<YOUR-KEY-ID>")
.credential(new DefaultAzureCredentialBuilder().build())
.buildAsyncClient();
CryptographyClientBuilder| Modifier and Type | Method and Description |
|---|---|
Mono<DecryptResult> |
decrypt(EncryptionAlgorithm algorithm,
byte[] cipherText)
Decrypts a single block of encrypted data using the configured key and specified algorithm.
|
Mono<EncryptResult> |
encrypt(EncryptionAlgorithm algorithm,
byte[] plaintext)
Encrypts an arbitrary sequence of bytes using the configured key.
|
Mono<SignResult> |
sign(SignatureAlgorithm algorithm,
byte[] digest)
Creates a signature from a digest using the configured key.
|
Mono<SignResult> |
signData(SignatureAlgorithm algorithm,
byte[] data)
Creates a signature from the raw data using the configured key.
|
Mono<UnwrapResult> |
unwrapKey(KeyWrapAlgorithm algorithm,
byte[] encryptedKey)
Unwraps a symmetric key using the configured key that was initially used for wrapping that key.
|
Mono<VerifyResult> |
verify(SignatureAlgorithm algorithm,
byte[] digest,
byte[] signature)
Verifies a signature using the configured key.
|
Mono<VerifyResult> |
verifyData(SignatureAlgorithm algorithm,
byte[] data,
byte[] signature)
Verifies a signature against the raw data using the configured key.
|
Mono<WrapResult> |
wrapKey(KeyWrapAlgorithm algorithm,
byte[] key)
Wraps a symmetric key using the configured key.
|
public Mono<EncryptResult> encrypt(EncryptionAlgorithm algorithm, byte[] plaintext)
The encryption algorithm indicates the type of algorithm to use for encrypting the
specified plaintext. Possible values for assymetric keys include:
RSA1_5, RSA_OAEP and
RSA_OAEP_256.
Possible values for symmetric keys include: A128CBC,
A128CBC-HS256, A192CBC,
A192CBC-HS384, A256CBC and
A256CBC-HS512
Code Samples
Encrypts the content. Subscribes to the call asynchronously and prints out the encrypted content details when a response has been received.
byte[] plainText = new byte[100];
new Random(0x1234567L).nextBytes(plainText);
cryptographyAsyncClient.encrypt(EncryptionAlgorithm.RSA_OAEP, plainText)
.subscriberContext(reactor.util.context.Context.of(key1, value1, key2, value2))
.subscribe(encryptResult ->
System.out.printf("Received encrypted content of length %d with algorithm %s \n",
encryptResult.getCipherText().length, encryptResult.getAlgorithm().toString()));
algorithm - The algorithm to be used for encryption.plaintext - The content to be encrypted.Mono containing a EncryptResult whose cipher text
contains the encrypted content.com.azure.core.exception.ResourceNotFoundException - if the key cannot be found for encryption.UnsupportedOperationException - if the encrypt operation is not supported or configured on the key.NullPointerException - if algorithm or plainText is null.public Mono<DecryptResult> decrypt(EncryptionAlgorithm algorithm, byte[] cipherText)
The encryption algorithm indicates the type of algorithm to use for decrypting the
specified encrypted content. Possible values for assymetric keys include:
RSA1_5, RSA_OAEP and RSA_OAEP_256.
Possible values for symmetric keys include: A128CBC,
A128CBC-HS256, A192CBC,
A192CBC-HS384, A256CBC and A256CBC-HS512
Code Samples
Decrypts the encrypted content. Subscribes to the call asynchronously and prints out the decrypted content details when a response has been received.
byte[] plainText = new byte[100];
new Random(0x1234567L).nextBytes(plainText);
cryptographyAsyncClient.decrypt(EncryptionAlgorithm.RSA_OAEP, plainText)
.subscriberContext(reactor.util.context.Context.of(key1, value1, key2, value2))
.subscribe(decryptResult ->
System.out.printf("Received decrypted content of length %d\n", decryptResult.getPlainText().length));
algorithm - The algorithm to be used for decryption.cipherText - The content to be decrypted.Mono containing the decrypted blob.com.azure.core.exception.ResourceNotFoundException - if the key cannot be found for decryption.UnsupportedOperationException - if the decrypt operation is not supported or configured on the key.NullPointerException - if algorithm or cipherText is null.public Mono<SignResult> sign(SignatureAlgorithm algorithm, byte[] digest)
The signature algorithm indicates the type of algorithm to use to create the
signature from the digest. Possible values include:
ES256, E384,
ES512, ES246K,
PS256, RS384,
RS512, RS256,
RS384 and RS512
Code Samples
Sings the digest. Subscribes to the call asynchronously and prints out the signature details when a response has been received.
byte[] data = new byte[100];
new Random(0x1234567L).nextBytes(data);
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(data);
byte[] digest = md.digest();
cryptographyAsyncClient.sign(SignatureAlgorithm.ES256, digest)
.subscriberContext(reactor.util.context.Context.of(key1, value1, key2, value2))
.subscribe(signResult ->
System.out.printf("Received signature of length %d with algorithm %s", signResult.getSignature().length));
algorithm - The algorithm to use for signing.digest - The content from which signature is to be created.Mono containing a SignResult whose signature contains
the created signature.com.azure.core.exception.ResourceNotFoundException - if the key cannot be found for signing.UnsupportedOperationException - if the sign operation is not supported or configured on the key.NullPointerException - if algorithm or digest is null.public Mono<VerifyResult> verify(SignatureAlgorithm algorithm, byte[] digest, byte[] signature)
The signature algorithm indicates the type of algorithm to use to verify the
signature. Possible values include:
ES256, E384, ES512, ES246K, PS256, RS384, RS512, RS256,
RS384 and RS512
Code Samples
Verifies the signature against the specified digest. Subscribes to the call asynchronously and prints out the verification details when a response has been received.
cryptographyAsyncClient.verify(SignatureAlgorithm.ES256, digest, signature)
.subscriberContext(reactor.util.context.Context.of(key1, value1, key2, value2))
.subscribe(verifyResult ->
System.out.printf("Verification status %s", verifyResult.isValid()));
algorithm - The algorithm to use for signing.digest - The content from which signature is to be created.signature - The signature to be verified.Mono containing a Boolean indicating the signature verification result.com.azure.core.exception.ResourceNotFoundException - if the key cannot be found for verifying.UnsupportedOperationException - if the verify operation is not supported or configured on the key.NullPointerException - if algorithm, digest or signature is null.public Mono<WrapResult> wrapKey(KeyWrapAlgorithm algorithm, byte[] key)
The wrap algorithm indicates the type of algorithm to use for wrapping the specified
key content. Possible values include:
RSA1_5, RSA_OAEP and RSA_OAEP_256
Code Samples
Wraps the key content. Subscribes to the call asynchronously and prints out the wrapped key details when a response has been received.
byte[] key = new byte[100];
new Random(0x1234567L).nextBytes(key);
cryptographyAsyncClient.wrapKey(KeyWrapAlgorithm.RSA_OAEP, key)
.subscriberContext(reactor.util.context.Context.of(key1, value1, key2, value2))
.subscribe(keyWrapResult ->
System.out.printf("Received encypted key of length %d with algorithm %s",
keyWrapResult.getEncryptedKey().length, keyWrapResult.getAlgorithm().toString()));
algorithm - The encryption algorithm to use for wrapping the key.key - The key content to be wrappedMono containing a WrapResult whose encrypted
key contains the wrapped key result.com.azure.core.exception.ResourceNotFoundException - if the key cannot be found for wrap operation.UnsupportedOperationException - if the wrap operation is not supported or configured on the key.NullPointerException - if algorithm or key is null.public Mono<UnwrapResult> unwrapKey(KeyWrapAlgorithm algorithm, byte[] encryptedKey)
The wrap algorithm indicates the type of algorithm to use for unwrapping the
specified encrypted key content. Possible values for asymmetric keys include:
RSA1_5, RSA_OAEP and RSA_OAEP_256.
Possible values for symmetric keys include: A128KW, A192KW and A256KW
Code Samples
Unwraps the key content. Subscribes to the call asynchronously and prints out the unwrapped key details when a response has been received.
cryptographyAsyncClient.unwrapKey(KeyWrapAlgorithm.RSA_OAEP, encryptedKey)
.subscriberContext(reactor.util.context.Context.of(key1, value1, key2, value2))
.subscribe(keyUnwrapResult ->
System.out.printf("Received key of length %d", keyUnwrapResult.getKey().length));
algorithm - The encryption algorithm to use for wrapping the key.encryptedKey - The encrypted key content to unwrap.Mono containing a the unwrapped key content.com.azure.core.exception.ResourceNotFoundException - if the key cannot be found for wrap operation.UnsupportedOperationException - if the unwrap operation is not supported or configured on the key.NullPointerException - if algorithm or encryptedKey is null.public Mono<SignResult> signData(SignatureAlgorithm algorithm, byte[] data)
The signature algorithm indicates the type of algorithm to use to sign the digest.
Possible values include:
ES256, E384, ES512, ES246K, PS256,
RS384, RS512, RS256, RS384 and
RS512
Code Samples
Signs the raw data. Subscribes to the call asynchronously and prints out the signature details when a response has been received.
byte[] data = new byte[100];
new Random(0x1234567L).nextBytes(data);
cryptographyAsyncClient.sign(SignatureAlgorithm.ES256, data)
.subscriberContext(reactor.util.context.Context.of(key1, value1, key2, value2))
.subscribe(signResult ->
System.out.printf("Received signature of length %d with algorithm %s", signResult.getSignature().length));
algorithm - The algorithm to use for signing.data - The content from which signature is to be created.Mono containing a SignResult whose signature contains
the created signature.com.azure.core.exception.ResourceNotFoundException - if the key cannot be found for signing.UnsupportedOperationException - if the sign operation is not supported or configured on the key.NullPointerException - if algorithm or data is null.public Mono<VerifyResult> verifyData(SignatureAlgorithm algorithm, byte[] data, byte[] signature)
The signature algorithm indicates the type of algorithm to use to verify the
signature. Possible values include:
ES256, E384, ES512, ES246K, PS256, RS384, RS512, RS256,
RS384 and RS512
Code Samples
Verifies the signature against the raw data. Subscribes to the call asynchronously and prints out the verification details when a response has been received.
cryptographyAsyncClient.verify(SignatureAlgorithm.ES256, data, signature)
.subscriberContext(reactor.util.context.Context.of(key1, value1, key2, value2))
.subscribe(verifyResult ->
System.out.printf("Verification status %s", verifyResult.isValid()));
algorithm - The algorithm to use for signing.data - The raw content against which signature is to be verified.signature - The signature to be verified.Boolean indicating the signature verification result.com.azure.core.exception.ResourceNotFoundException - if the key cannot be found for verifying.UnsupportedOperationException - if the verify operation is not supported or configured on the key.NullPointerException - if algorithm, data or signature is null.Copyright © 2021 Microsoft Corporation. All rights reserved.