use of com.microsoft.azure.keyvault.KeyIdentifier in project azure-sdk-for-java by Azure.
the class KeyOperationsTest method encryptDecryptOperations.
@Test
public void encryptDecryptOperations() throws Exception {
JsonWebKey testKey = importTestKey();
KeyIdentifier keyId = new KeyIdentifier(testKey.kid());
// Test variables
byte[] plainText = new byte[100];
new Random(0x1234567L).nextBytes(plainText);
byte[] cipherText;
KeyOperationResult result;
// encrypt and decrypt using kid WO version
{
result = keyVaultClient.encrypt(keyId.baseIdentifier(), JsonWebKeyEncryptionAlgorithm.RSA_OAEP, plainText);
cipherText = result.result();
result = keyVaultClient.decrypt(keyId.baseIdentifier(), JsonWebKeyEncryptionAlgorithm.RSA_OAEP, cipherText);
Assert.assertArrayEquals(plainText, result.result());
}
// encrypt and decrypt using full kid
{
result = keyVaultClient.encrypt(testKey.kid(), JsonWebKeyEncryptionAlgorithm.RSA_OAEP, plainText);
cipherText = result.result();
result = keyVaultClient.decrypt(testKey.kid(), JsonWebKeyEncryptionAlgorithm.RSA_OAEP, cipherText);
Assert.assertArrayEquals(plainText, result.result());
}
}
Aggregations