Skip to content

Commit b637d40

Browse files
authored
Added support for encryption algorithms for symmetric keys (Azure#17209)
* 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.
1 parent 6955838 commit b637d40

File tree

50 files changed

+2297
-403
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2297
-403
lines changed

eng/code-quality-reports/src/main/resources/checkstyle/checkstyle-suppressions.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,10 @@
348348
<!-- InvalidKeyException is not a runtime exception, issue link: https://github.com/Azure/azure-sdk-for-java/issues/5178 -->
349349
<suppress checks="com.azure.tools.checkstyle.checks.ThrowFromClientLogger"
350350
files="com.azure.security.keyvault.keys.cryptography.AesCbc.java"/>
351+
<suppress checks="com.azure.tools.checkstyle.checks.ThrowFromClientLogger"
352+
files="com.azure.security.keyvault.keys.cryptography.AesCbcPad.java"/>
353+
<suppress checks="com.azure.tools.checkstyle.checks.ThrowFromClientLogger"
354+
files="com.azure.security.keyvault.keys.cryptography.AesGcm.java"/>
351355

352356
<!-- suppress the runtime exception in the KeyVaultClient class-->
353357
<suppress checks="com.azure.tools.checkstyle.checks.ThrowFromClientLogger"

eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2390,7 +2390,7 @@
23902390
<Method name="getUserName" />
23912391
<Bug pattern="NM_CONFUSING" />
23922392
</Match>
2393-
2393+
23942394
<!-- Disabling false positives in azure-core -->
23952395
<!-- This Issue has been resolved as per spotbugs's recommended solution but the static checker still flags it, its a known issue with this rule. -->
23962396
<Match>
@@ -2421,4 +2421,13 @@
24212421
<Method name="~(get|post)" />
24222422
<Bug pattern="RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE" />
24232423
</Match>
2424+
2425+
<!-- Conflicting APIs have already been GA'd with incorrect capitalization -->
2426+
<Match>
2427+
<Or>
2428+
<Class name="com.azure.security.keyvault.keys.cryptography.DecryptOptions" />
2429+
<Class name="com.azure.security.keyvault.keys.cryptography.EncryptOptions" />
2430+
</Or>
2431+
<Bug pattern="NM_CONFUSING" />
2432+
</Match>
24242433
</FindBugsFilter>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.security.keyvault.keys.cryptography;
5+
6+
class Aes128CbcPad extends AesCbcPad {
7+
private static final int KEY_SIZE = 128;
8+
public static final String ALGORITHM_NAME = "A128CBCPAD";
9+
10+
Aes128CbcPad() {
11+
super(ALGORITHM_NAME, KEY_SIZE);
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.security.keyvault.keys.cryptography;
5+
6+
class Aes128Gcm extends AesGcm {
7+
private static final int KEY_SIZE = 128;
8+
public static final String ALGORITHM_NAME = "A128GCM";
9+
10+
Aes128Gcm() {
11+
super(ALGORITHM_NAME, KEY_SIZE);
12+
}
13+
}

sdk/keyvault/azure-security-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/cryptography/AesKw128.java renamed to sdk/keyvault/azure-security-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/cryptography/Aes128Kw.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
import java.security.Provider;
1111
import java.util.Arrays;
1212

13-
class AesKw128 extends AesKw {
13+
class Aes128Kw extends AesKw {
1414

1515
public static final String ALGORITHM_NAME = "A128KW";
1616

1717
static final int KEY_SIZE_IN_BYTES = 128 >> 3;
1818

19-
AesKw128() {
19+
Aes128Kw() {
2020
super(ALGORITHM_NAME);
2121
}
2222

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.security.keyvault.keys.cryptography;
5+
6+
class Aes192CbcPad extends AesCbcPad {
7+
private static final int KEY_SIZE = 192;
8+
public static final String ALGORITHM_NAME = "A192CBCPAD";
9+
10+
Aes192CbcPad() {
11+
super(ALGORITHM_NAME, KEY_SIZE);
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.security.keyvault.keys.cryptography;
5+
6+
class Aes192Gcm extends AesGcm {
7+
private static final int KEY_SIZE = 192;
8+
public static final String ALGORITHM_NAME = "A192GCM";
9+
10+
Aes192Gcm() {
11+
super(ALGORITHM_NAME, KEY_SIZE);
12+
}
13+
}

sdk/keyvault/azure-security-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/cryptography/AesKw192.java renamed to sdk/keyvault/azure-security-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/cryptography/Aes192Kw.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
import java.security.Provider;
1111
import java.util.Arrays;
1212

13-
class AesKw192 extends AesKw {
13+
class Aes192Kw extends AesKw {
1414

1515
public static final String ALGORITHM_NAME = "A192KW";
1616

1717
static final int KEY_SIZE_IN_BYTES = 192 >> 3;
1818

19-
AesKw192() {
19+
Aes192Kw() {
2020
super(ALGORITHM_NAME);
2121
}
2222

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.security.keyvault.keys.cryptography;
5+
6+
class Aes256CbcPad extends AesCbcPad {
7+
private static final int KEY_SIZE = 256;
8+
public static final String ALGORITHM_NAME = "A256CBCPAD";
9+
10+
Aes256CbcPad() {
11+
super(ALGORITHM_NAME, KEY_SIZE);
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.security.keyvault.keys.cryptography;
5+
6+
class Aes256Gcm extends AesGcm {
7+
private static final int KEY_SIZE = 256;
8+
public static final String ALGORITHM_NAME = "A256GCM";
9+
10+
Aes256Gcm() {
11+
super(ALGORITHM_NAME, KEY_SIZE);
12+
}
13+
}

0 commit comments

Comments
 (0)