Skip to content

Commit 41c122a

Browse files
authored
[Key Vault] Add warnings on RSA1_5 and RSA_OAEP encryption algorithms (Azure#48005)
* Add warnings on RSA1_5 and RSA_OAEP algorithms * Replace REST constants with C# names * missing '/' in XML see tag * Chaning missing REST name to property name * Update samples to use RsaOaep256 * Update code snippets * Add Obsolete attribute * Update API * Revert "Update API" This reverts commit ae38e80. * Revert "Add Obsolete attribute" This reverts commit 88e2a7c.
1 parent fc77ea0 commit 41c122a

File tree

6 files changed

+24
-10
lines changed

6 files changed

+24
-10
lines changed

sdk/keyvault/Azure.Security.KeyVault.Keys/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,10 @@ var cryptoClient = client.GetCryptographyClient(key.Name, key.Properties.Version
283283
byte[] plaintext = Encoding.UTF8.GetBytes("A single block of plaintext");
284284

285285
// encrypt the data using the algorithm RSAOAEP
286-
EncryptResult encryptResult = cryptoClient.Encrypt(EncryptionAlgorithm.RsaOaep, plaintext);
286+
EncryptResult encryptResult = cryptoClient.Encrypt(EncryptionAlgorithm.RsaOaep256, plaintext);
287287

288288
// decrypt the encrypted data.
289-
DecryptResult decryptResult = cryptoClient.Decrypt(EncryptionAlgorithm.RsaOaep, encryptResult.Ciphertext);
289+
DecryptResult decryptResult = cryptoClient.Decrypt(EncryptionAlgorithm.RsaOaep256, encryptResult.Ciphertext);
290290
```
291291

292292
### Create a key asynchronously

sdk/keyvault/Azure.Security.KeyVault.Keys/samples/Sample4_EncryptDecrypt.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Note that RSA encryption algorithms have no chaining so they can only encrypt a
4545

4646
```C# Snippet:KeysSample4EncryptKey
4747
byte[] plaintext = Encoding.UTF8.GetBytes("A single block of plaintext");
48-
EncryptResult encryptResult = cryptoClient.Encrypt(EncryptionAlgorithm.RsaOaep, plaintext);
48+
EncryptResult encryptResult = cryptoClient.Encrypt(EncryptionAlgorithm.RsaOaep256, plaintext);
4949
Debug.WriteLine($"Encrypted data using the algorithm {encryptResult.Algorithm}, with key {encryptResult.KeyId}. The resulting encrypted data is {Convert.ToBase64String(encryptResult.Ciphertext)}");
5050
```
5151

@@ -54,7 +54,7 @@ Debug.WriteLine($"Encrypted data using the algorithm {encryptResult.Algorithm},
5454
Now decrypt the encrypted data. Note that the same algorithm must always be used for both encrypt and decrypt.
5555

5656
```C# Snippet:KeysSample4DecryptKey
57-
DecryptResult decryptResult = cryptoClient.Decrypt(EncryptionAlgorithm.RsaOaep, encryptResult.Ciphertext);
57+
DecryptResult decryptResult = cryptoClient.Decrypt(EncryptionAlgorithm.RsaOaep256, encryptResult.Ciphertext);
5858
Debug.WriteLine($"Decrypted data using the algorithm {decryptResult.Algorithm}, with key {decryptResult.KeyId}. The resulting decrypted data is {Encoding.UTF8.GetString(decryptResult.Plaintext)}");
5959
```
6060

sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/EncryptionAlgorithm.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,26 @@ public EncryptionAlgorithm(string value)
3737
}
3838

3939
/// <summary>
40+
/// <para>
41+
/// <b>[Not recommended]</b>
4042
/// Gets an RSA1_5 <see cref="EncryptionAlgorithm"/>.
43+
/// </para><para>
44+
/// Microsoft recommends using <see cref="EncryptionAlgorithm.RsaOaep256"/> or stronger algorithms for enhanced security.
45+
/// Microsoft does <b>not</b> recommend <see cref="EncryptionAlgorithm.Rsa15"/>, which is included solely for backwards compatibility.
46+
/// Cryptographic standards no longer consider RSA with the PKCS#1 v1.5 padding scheme secure for encryption.
47+
/// </para>
4148
/// </summary>
4249
public static EncryptionAlgorithm Rsa15 { get; } = new EncryptionAlgorithm(Rsa15Value);
4350

4451
/// <summary>
52+
/// <para>
53+
/// <b>[Not recommended]</b>
4554
/// Gets an RSA-OAEP <see cref="EncryptionAlgorithm"/>.
55+
/// </para><para>
56+
/// Microsoft recommends using <see cref="EncryptionAlgorithm.RsaOaep256"/> or stronger algorithms for enhanced security.
57+
/// Microsoft does <b>not</b> recommend <see cref="EncryptionAlgorithm.RsaOaep"/>, which is included solely for backwards compatibility.
58+
/// <see cref="EncryptionAlgorithm.RsaOaep"/> utilizes SHA1, which has known collision problems.
59+
/// </para>
4660
/// </summary>
4761
public static EncryptionAlgorithm RsaOaep { get; } = new EncryptionAlgorithm(RsaOaepValue);
4862

sdk/keyvault/Azure.Security.KeyVault.Keys/tests/samples/Sample4_EncryptDecrypt.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ public void EncryptDecryptSync()
4444

4545
#region Snippet:KeysSample4EncryptKey
4646
byte[] plaintext = Encoding.UTF8.GetBytes("A single block of plaintext");
47-
EncryptResult encryptResult = cryptoClient.Encrypt(EncryptionAlgorithm.RsaOaep, plaintext);
47+
EncryptResult encryptResult = cryptoClient.Encrypt(EncryptionAlgorithm.RsaOaep256, plaintext);
4848
Debug.WriteLine($"Encrypted data using the algorithm {encryptResult.Algorithm}, with key {encryptResult.KeyId}. The resulting encrypted data is {Convert.ToBase64String(encryptResult.Ciphertext)}");
4949
#endregion
5050

5151
#region Snippet:KeysSample4DecryptKey
52-
DecryptResult decryptResult = cryptoClient.Decrypt(EncryptionAlgorithm.RsaOaep, encryptResult.Ciphertext);
52+
DecryptResult decryptResult = cryptoClient.Decrypt(EncryptionAlgorithm.RsaOaep256, encryptResult.Ciphertext);
5353
Debug.WriteLine($"Decrypted data using the algorithm {decryptResult.Algorithm}, with key {decryptResult.KeyId}. The resulting decrypted data is {Encoding.UTF8.GetString(decryptResult.Plaintext)}");
5454
#endregion
5555

sdk/keyvault/Azure.Security.KeyVault.Keys/tests/samples/Sample4_EncryptDecryptAsync.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ public async Task EncryptDecryptAsync()
4747
byte[] plaintext = Encoding.UTF8.GetBytes("A single block of plaintext");
4848

4949
// First encrypt the data using RSAOAEP with the created key.
50-
EncryptResult encryptResult = await cryptoClient.EncryptAsync(EncryptionAlgorithm.RsaOaep, plaintext);
50+
EncryptResult encryptResult = await cryptoClient.EncryptAsync(EncryptionAlgorithm.RsaOaep256, plaintext);
5151
Debug.WriteLine($"Encrypted data using the algorithm {encryptResult.Algorithm}, with key {encryptResult.KeyId}. The resulting encrypted data is {Convert.ToBase64String(encryptResult.Ciphertext)}");
5252

5353
// Now decrypt the encrypted data. Note that the same algorithm must always be used for both encrypt and decrypt
54-
DecryptResult decryptResult = await cryptoClient.DecryptAsync(EncryptionAlgorithm.RsaOaep, encryptResult.Ciphertext);
54+
DecryptResult decryptResult = await cryptoClient.DecryptAsync(EncryptionAlgorithm.RsaOaep256, encryptResult.Ciphertext);
5555
Debug.WriteLine($"Decrypted data using the algorithm {decryptResult.Algorithm}, with key {decryptResult.KeyId}. The resulting decrypted data is {Encoding.UTF8.GetString(decryptResult.Plaintext)}");
5656

5757
// The Cloud RSA Key is no longer needed, need to delete it from the Key Vault.

sdk/keyvault/Azure.Security.KeyVault.Keys/tests/samples/SampleSnippets.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,10 @@ public void EncryptDecrypt()
187187
byte[] plaintext = Encoding.UTF8.GetBytes("A single block of plaintext");
188188

189189
// encrypt the data using the algorithm RSAOAEP
190-
EncryptResult encryptResult = cryptoClient.Encrypt(EncryptionAlgorithm.RsaOaep, plaintext);
190+
EncryptResult encryptResult = cryptoClient.Encrypt(EncryptionAlgorithm.RsaOaep256, plaintext);
191191

192192
// decrypt the encrypted data.
193-
DecryptResult decryptResult = cryptoClient.Decrypt(EncryptionAlgorithm.RsaOaep, encryptResult.Ciphertext);
193+
DecryptResult decryptResult = cryptoClient.Decrypt(EncryptionAlgorithm.RsaOaep256, encryptResult.Ciphertext);
194194
#endregion
195195
}
196196

0 commit comments

Comments
 (0)