Search in sources :

Example 6 with KeyIdentifier

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());
    }
}
Also used : KeyIdentifier(com.microsoft.azure.keyvault.KeyIdentifier) Random(java.util.Random) KeyOperationResult(com.microsoft.azure.keyvault.models.KeyOperationResult) JsonWebKey(com.microsoft.azure.keyvault.webkey.JsonWebKey) Test(org.junit.Test)

Aggregations

KeyIdentifier (com.microsoft.azure.keyvault.KeyIdentifier)6 Test (org.junit.Test)6 KeyBundle (com.microsoft.azure.keyvault.models.KeyBundle)3 KeyOperationResult (com.microsoft.azure.keyvault.models.KeyOperationResult)3 KeyVaultErrorException (com.microsoft.azure.keyvault.models.KeyVaultErrorException)3 JsonWebKey (com.microsoft.azure.keyvault.webkey.JsonWebKey)3 Random (java.util.Random)3 DateTime (org.joda.time.DateTime)2 PagedList (com.microsoft.azure.PagedList)1 SecretIdentifier (com.microsoft.azure.keyvault.SecretIdentifier)1 Attributes (com.microsoft.azure.keyvault.models.Attributes)1 CertificateAttributes (com.microsoft.azure.keyvault.models.CertificateAttributes)1 CertificateBundle (com.microsoft.azure.keyvault.models.CertificateBundle)1 CertificateOperation (com.microsoft.azure.keyvault.models.CertificateOperation)1 CertificatePolicy (com.microsoft.azure.keyvault.models.CertificatePolicy)1 IssuerParameters (com.microsoft.azure.keyvault.models.IssuerParameters)1 KeyItem (com.microsoft.azure.keyvault.models.KeyItem)1 KeyVerifyResult (com.microsoft.azure.keyvault.models.KeyVerifyResult)1 SecretBundle (com.microsoft.azure.keyvault.models.SecretBundle)1 SecretProperties (com.microsoft.azure.keyvault.models.SecretProperties)1