Skip to content

Commit 65f70ec

Browse files
authored
Added small changes that missed PR Azure#17209 (Azure#17552)
* Added support for encryption AES encryption algorithms. * Added CryptographyOptions and ensured the initialization vector is populated before attempting to perform any local cryptography operations on symmetric keys. * Added APIs that accept CryptographyOptions to CryptographyClient. * Fixed Javadoc issues. * Fixed checkstyle issues. Added samples. * Added checkstyle exceptions. * Fixed test and spotbugs issues. * Applied PR feedback and added local tests. * Made the EncryptOptions and DecryptOptions constructor package-private, as well as their children's, and made them have factory methods for creating the former to help with discoverability. * Fixed build issues. * Changed EncryptOptions and DecryptOptions to use a factory model. * Added iv, additionalAuthenticatedDate and authenticationTag to EncryptResult. * Made `plainText` and `cipherText` all lowercase. * Reverted capitalization change. * Added null check for `iv` in local decryption.
1 parent eb98c16 commit 65f70ec

File tree

15 files changed

+188
-194
lines changed

15 files changed

+188
-194
lines changed

sdk/keyvault/azure-security-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/cryptography/AesCbc.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ static class AesCbcEncryptor implements ICryptoTransform {
4343
}
4444

4545
@Override
46-
public byte[] doFinal(byte[] plaintext) throws IllegalBlockSizeException, BadPaddingException {
47-
return cipher.doFinal(plaintext);
46+
public byte[] doFinal(byte[] plainText) throws IllegalBlockSizeException, BadPaddingException {
47+
return cipher.doFinal(plainText);
4848
}
4949
}
5050

@@ -65,8 +65,8 @@ static class AesCbcDecryptor implements ICryptoTransform {
6565
}
6666

6767
@Override
68-
public byte[] doFinal(byte[] plaintext) throws IllegalBlockSizeException, BadPaddingException {
69-
return cipher.doFinal(plaintext);
68+
public byte[] doFinal(byte[] plainText) throws IllegalBlockSizeException, BadPaddingException {
69+
return cipher.doFinal(plainText);
7070
}
7171
}
7272

sdk/keyvault/azure-security-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/cryptography/AesCbcPad.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ static class AesCbcPadEncryptor implements ICryptoTransform {
4343
}
4444

4545
@Override
46-
public byte[] doFinal(byte[] plaintext) throws IllegalBlockSizeException, BadPaddingException {
47-
return cipher.doFinal(plaintext);
46+
public byte[] doFinal(byte[] plainText) throws IllegalBlockSizeException, BadPaddingException {
47+
return cipher.doFinal(plainText);
4848
}
4949
}
5050

@@ -65,8 +65,8 @@ static class AesCbcPadDecryptor implements ICryptoTransform {
6565
}
6666

6767
@Override
68-
public byte[] doFinal(byte[] plaintext) throws IllegalBlockSizeException, BadPaddingException {
69-
return cipher.doFinal(plaintext);
68+
public byte[] doFinal(byte[] plainText) throws IllegalBlockSizeException, BadPaddingException {
69+
return cipher.doFinal(plainText);
7070
}
7171
}
7272

sdk/keyvault/azure-security-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/cryptography/AesGcm.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ static class AesGcmEncryptor implements ICryptoTransform {
4747
}
4848

4949
@Override
50-
public byte[] doFinal(byte[] plaintext) throws IllegalBlockSizeException, BadPaddingException {
51-
return cipher.doFinal(plaintext);
50+
public byte[] doFinal(byte[] plainText) throws IllegalBlockSizeException, BadPaddingException {
51+
return cipher.doFinal(plainText);
5252
}
5353
}
5454

@@ -75,8 +75,8 @@ static class AesGcmDecryptor implements ICryptoTransform {
7575
}
7676

7777
@Override
78-
public byte[] doFinal(byte[] plaintext) throws IllegalBlockSizeException, BadPaddingException {
79-
return cipher.doFinal(plaintext);
78+
public byte[] doFinal(byte[] plainText) throws IllegalBlockSizeException, BadPaddingException {
79+
return cipher.doFinal(plainText);
8080
}
8181
}
8282

sdk/keyvault/azure-security-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/cryptography/AesKw.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ static class AesKwDecryptor implements ICryptoTransform {
4848
}
4949

5050
@Override
51-
public byte[] doFinal(byte[] plaintext)
51+
public byte[] doFinal(byte[] plainText)
5252
throws IllegalBlockSizeException, BadPaddingException, InvalidKeyException, NoSuchAlgorithmException {
5353

54-
return cipher.unwrap(plaintext, "AESWrap", Cipher.SECRET_KEY).getEncoded();
54+
return cipher.unwrap(plainText, "AESWrap", Cipher.SECRET_KEY).getEncoded();
5555
}
5656

5757
}
@@ -81,10 +81,10 @@ static class AesKwEncryptor implements ICryptoTransform {
8181
}
8282

8383
@Override
84-
public byte[] doFinal(byte[] plaintext)
84+
public byte[] doFinal(byte[] plainText)
8585
throws IllegalBlockSizeException, BadPaddingException, InvalidKeyException {
8686

87-
return cipher.wrap(new SecretKeySpec(plaintext, "AES"));
87+
return cipher.wrap(new SecretKeySpec(plainText, "AES"));
8888
}
8989

9090
}

sdk/keyvault/azure-security-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/cryptography/CryptographyAsyncClient.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ Mono<JsonWebKey> getSecretKey() {
196196
* portion of the key is used for encryption. This operation requires the keys/encrypt permission.
197197
*
198198
* <p>The {@link EncryptionAlgorithm encryption algorithm} indicates the type of algorithm to use for encrypting the
199-
* specified {@code plaintext}. Possible values for asymmetric keys include:
199+
* specified {@code plainText}. Possible values for asymmetric keys include:
200200
* {@link EncryptionAlgorithm#RSA1_5 RSA1_5}, {@link EncryptionAlgorithm#RSA_OAEP RSA_OAEP} and
201201
* {@link EncryptionAlgorithm#RSA_OAEP_256 RSA_OAEP_256}.
202202
*
@@ -214,16 +214,16 @@ Mono<JsonWebKey> getSecretKey() {
214214
* {@codesnippet com.azure.security.keyvault.keys.cryptography.CryptographyAsyncClient.encrypt#EncryptionAlgorithm-byte}
215215
*
216216
* @param algorithm The algorithm to be used for encryption.
217-
* @param plaintext The content to be encrypted.
217+
* @param plainText The content to be encrypted.
218218
* @return A {@link Mono} containing a {@link EncryptResult} whose {@link EncryptResult#getCipherText() cipher text}
219219
* contains the encrypted content.
220220
* @throws ResourceNotFoundException If the key cannot be found for encryption.
221221
* @throws UnsupportedOperationException If the encrypt operation is not supported or configured on the key.
222-
* @throws NullPointerException If {@code algorithm} or {@code plaintext} are {@code null}.
222+
* @throws NullPointerException If {@code algorithm} or {@code plainText} are {@code null}.
223223
*/
224224
@ServiceMethod(returns = ReturnType.SINGLE)
225-
public Mono<EncryptResult> encrypt(EncryptionAlgorithm algorithm, byte[] plaintext) {
226-
return encrypt(new EncryptOptions(algorithm, plaintext, null, null), null);
225+
public Mono<EncryptResult> encrypt(EncryptionAlgorithm algorithm, byte[] plainText) {
226+
return encrypt(new EncryptOptions(algorithm, plainText, null, null), null);
227227
}
228228

229229
/**
@@ -233,7 +233,7 @@ public Mono<EncryptResult> encrypt(EncryptionAlgorithm algorithm, byte[] plainte
233233
* portion of the key is used for encryption. This operation requires the keys/encrypt permission.
234234
*
235235
* <p>The {@link EncryptionAlgorithm encryption algorithm} indicates the type of algorithm to use for encrypting the
236-
* specified {@code plaintext}. Possible values for asymmetric keys include:
236+
* specified {@code plainText}. Possible values for asymmetric keys include:
237237
* {@link EncryptionAlgorithm#RSA1_5 RSA1_5}, {@link EncryptionAlgorithm#RSA_OAEP RSA_OAEP} and
238238
* {@link EncryptionAlgorithm#RSA_OAEP_256 RSA_OAEP_256}.
239239
*
@@ -309,15 +309,15 @@ Mono<EncryptResult> encrypt(EncryptOptions encryptOptions, Context context) {
309309
* {@codesnippet com.azure.security.keyvault.keys.cryptography.CryptographyAsyncClient.decrypt#EncryptionAlgorithm-byte}
310310
*
311311
* @param algorithm The algorithm to be used for decryption.
312-
* @param ciphertext The content to be decrypted.
312+
* @param cipherText The content to be decrypted.
313313
* @return A {@link Mono} containing the decrypted blob.
314314
* @throws ResourceNotFoundException If the key cannot be found for decryption.
315315
* @throws UnsupportedOperationException If the decrypt operation is not supported or configured on the key.
316-
* @throws NullPointerException If {@code algorithm} or {@code ciphertext} are {@code null}.
316+
* @throws NullPointerException If {@code algorithm} or {@code cipherText} are {@code null}.
317317
*/
318318
@ServiceMethod(returns = ReturnType.SINGLE)
319-
public Mono<DecryptResult> decrypt(EncryptionAlgorithm algorithm, byte[] ciphertext) {
320-
return decrypt(new DecryptOptions(algorithm, ciphertext, null, null, null));
319+
public Mono<DecryptResult> decrypt(EncryptionAlgorithm algorithm, byte[] cipherText) {
320+
return decrypt(new DecryptOptions(algorithm, cipherText, null, null, null));
321321
}
322322

323323
/**

sdk/keyvault/azure-security-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/cryptography/CryptographyClient.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,16 @@ public Response<KeyVaultKey> getKeyWithResponse(Context context) {
102102
* {@codesnippet com.azure.security.keyvault.keys.cryptography.CryptographyClient.encrypt#EncryptionAlgorithm-byte-Context}
103103
*
104104
* @param algorithm The algorithm to be used for encryption.
105-
* @param plaintext The content to be encrypted.
105+
* @param plainText The content to be encrypted.
106106
* @param context Additional context that is passed through the Http pipeline during the service call.
107107
* @return A {@link EncryptResult} whose {@link EncryptResult#getCipherText() cipher text} contains the encrypted
108108
* content.
109109
* @throws ResourceNotFoundException If the key cannot be found for encryption.
110110
* @throws UnsupportedOperationException If the encrypt operation is not supported or configured on the key.
111-
* @throws NullPointerException If {@code algorithm} or {@code plaintext} are {@code null}.
111+
* @throws NullPointerException If {@code algorithm} or {@code plainText} are {@code null}.
112112
*/
113-
public EncryptResult encrypt(EncryptionAlgorithm algorithm, byte[] plaintext, Context context) {
114-
return encrypt(new EncryptOptions(algorithm, plaintext, null, null), context);
113+
public EncryptResult encrypt(EncryptionAlgorithm algorithm, byte[] plainText, Context context) {
114+
return encrypt(new EncryptOptions(algorithm, plainText, null, null), context);
115115
}
116116

117117
/**
@@ -139,15 +139,15 @@ public EncryptResult encrypt(EncryptionAlgorithm algorithm, byte[] plaintext, Co
139139
* {@codesnippet com.azure.security.keyvault.keys.cryptography.CryptographyClient.encrypt#EncryptionAlgorithm-byte}
140140
*
141141
* @param algorithm The algorithm to be used for encryption.
142-
* @param plaintext The content to be encrypted.
142+
* @param plainText The content to be encrypted.
143143
* @return The {@link EncryptResult} whose {@link EncryptResult#getCipherText() cipher text} contains the encrypted
144144
* content.
145145
* @throws ResourceNotFoundException If the key cannot be found for encryption.
146146
* @throws UnsupportedOperationException If the encrypt operation is not supported or configured on the key.
147-
* @throws NullPointerException If {@code algorithm} or {@code plaintext} are {@code null}.
147+
* @throws NullPointerException If {@code algorithm} or {@code plainText} are {@code null}.
148148
*/
149-
public EncryptResult encrypt(EncryptionAlgorithm algorithm, byte[] plaintext) {
150-
return encrypt(algorithm, plaintext, Context.NONE);
149+
public EncryptResult encrypt(EncryptionAlgorithm algorithm, byte[] plainText) {
150+
return encrypt(algorithm, plainText, Context.NONE);
151151
}
152152

153153
/**
@@ -211,15 +211,15 @@ public EncryptResult encrypt(EncryptOptions encryptOptions, Context context) {
211211
* {@codesnippet com.azure.security.keyvault.keys.cryptography.CryptographyClient.decrypt#EncryptionAlgorithm-byte-Context}
212212
*
213213
* @param algorithm The algorithm to be used for decryption.
214-
* @param ciphertext The content to be decrypted.
214+
* @param cipherText The content to be decrypted.
215215
* @param context Additional context that is passed through the Http pipeline during the service call.
216216
* @return The decrypted blob.
217217
* @throws ResourceNotFoundException If the key cannot be found for encryption.
218218
* @throws UnsupportedOperationException If the decrypt operation is not supported or configured on the key.
219-
* @throws NullPointerException If {@code algorithm} or {@code ciphertext} are {@code null}.
219+
* @throws NullPointerException If {@code algorithm} or {@code cipherText} are {@code null}.
220220
*/
221-
public DecryptResult decrypt(EncryptionAlgorithm algorithm, byte[] ciphertext, Context context) {
222-
return decrypt(new DecryptOptions(algorithm, ciphertext, null, null, null), context);
221+
public DecryptResult decrypt(EncryptionAlgorithm algorithm, byte[] cipherText, Context context) {
222+
return decrypt(new DecryptOptions(algorithm, cipherText, null, null, null), context);
223223
}
224224

225225
/**
@@ -247,14 +247,14 @@ public DecryptResult decrypt(EncryptionAlgorithm algorithm, byte[] ciphertext, C
247247
* {@codesnippet com.azure.security.keyvault.keys.cryptography.CryptographyClient.decrypt#EncryptionAlgorithm-byte}
248248
*
249249
* @param algorithm The algorithm to be used for decryption.
250-
* @param ciphertext The content to be decrypted.
250+
* @param cipherText The content to be decrypted.
251251
* @return The decrypted blob.
252252
* @throws ResourceNotFoundException If the key cannot be found for encryption.
253253
* @throws UnsupportedOperationException If the decrypt operation is not supported or configured on the key.
254-
* @throws NullPointerException If {@code algorithm} or {@code ciphertext} are {@code null}.
254+
* @throws NullPointerException If {@code algorithm} or {@code cipherText} are {@code null}.
255255
*/
256-
public DecryptResult decrypt(EncryptionAlgorithm algorithm, byte[] ciphertext) {
257-
return decrypt(new DecryptOptions(algorithm, ciphertext, null, null, null), Context.NONE);
256+
public DecryptResult decrypt(EncryptionAlgorithm algorithm, byte[] cipherText) {
257+
return decrypt(new DecryptOptions(algorithm, cipherText, null, null, null), Context.NONE);
258258
}
259259

260260
/**

sdk/keyvault/azure-security-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/cryptography/CryptographyServiceClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ Mono<EncryptResult> encrypt(EncryptOptions encryptOptions, Context context) {
133133
byte[] authenticatedData = encryptOptions.getAdditionalAuthenticatedData();
134134
KeyOperationParameters parameters = new KeyOperationParameters()
135135
.setAlgorithm(algorithm)
136-
.setValue(encryptOptions.getPlaintext())
136+
.setValue(encryptOptions.getPlainText())
137137
.setIv(iv)
138138
.setAdditionalAuthenticatedData(authenticatedData);
139139
context = context == null ? Context.NONE : context;
@@ -158,7 +158,7 @@ Mono<DecryptResult> decrypt(DecryptOptions decryptOptions, Context context) {
158158
byte[] authenticationTag = decryptOptions.getAuthenticationTag();
159159
KeyOperationParameters parameters = new KeyOperationParameters()
160160
.setAlgorithm(algorithm)
161-
.setValue(decryptOptions.getCiphertext())
161+
.setValue(decryptOptions.getCipherText())
162162
.setIv(iv)
163163
.setAdditionalAuthenticatedData(additionalAuthenticatedData)
164164
.setAuthenticationTag(authenticationTag);

0 commit comments

Comments
 (0)