CryptographyClient (Azure SDK for Java Reference Documentation)
Jessica Wood
Published Feb 16, 2026
Encrypts an arbitrary sequence of bytes using the configured key. Note that the encrypt operation only supports a single block of data, the size of which is dependent on the target key and the encryption algorithm to be used. The encrypt operation is supported for both symmetric keys and asymmetric keys. In case of asymmetric keys public portion of the key is used for encryption. This operation requires the keys/encrypt permission.
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
Encrypts the content. Subscribes to the call asynchronously and prints out the encrypted content details when a response has been received.
byte[] plainTextToEncrypt = new byte[100]; new Random(0x1234567L).nextBytes(plainTextToEncrypt); EncryptResult encryptionResult = cryptographyClient.encrypt(EncryptionAlgorithm.RSA_OAEP, plainTextToEncrypt, new Context(key1, value1)); System.out.printf("Received encrypted content of length %d with algorithm %s \n", encryptionResult.getCipherText().length, encryptionResult.getAlgorithm().toString());