Fix CNG persisted symmetric key operations
authorJeremy Barton <jbarton@microsoft.com>
Thu, 23 Jul 2020 15:19:04 +0000 (08:19 -0700)
committerGitHub <noreply@github.com>
Thu, 23 Jul 2020 15:19:04 +0000 (08:19 -0700)
During a code cleanup the encoding changed from UTF-16LE
to UTF-8, which is not valid for the P/Invoke.

src/libraries/System.Security.Cryptography.Cng/src/Internal/Cryptography/BasicSymmetricCipherNCrypt.cs
src/libraries/System.Security.Cryptography.Cng/tests/AesCngTests.cs
src/libraries/System.Security.Cryptography.Cng/tests/TripleDESCngTests.cs

index 4775435..9b88e7e 100644 (file)
@@ -112,8 +112,8 @@ namespace Internal.Cryptography
         private readonly bool _encrypting;
 
         private static readonly CngProperty s_ECBMode =
-            new CngProperty(Interop.NCrypt.NCRYPT_CHAINING_MODE_PROPERTY, Encoding.UTF8.GetBytes(Interop.BCrypt.BCRYPT_CHAIN_MODE_ECB + "\0"), CngPropertyOptions.None);
+            new CngProperty(Interop.NCrypt.NCRYPT_CHAINING_MODE_PROPERTY, Encoding.Unicode.GetBytes(Interop.BCrypt.BCRYPT_CHAIN_MODE_ECB + "\0"), CngPropertyOptions.None);
         private static readonly CngProperty s_CBCMode =
-            new CngProperty(Interop.NCrypt.NCRYPT_CHAINING_MODE_PROPERTY, Encoding.UTF8.GetBytes(Interop.BCrypt.BCRYPT_CHAIN_MODE_CBC + "\0"), CngPropertyOptions.None);
+            new CngProperty(Interop.NCrypt.NCRYPT_CHAINING_MODE_PROPERTY, Encoding.Unicode.GetBytes(Interop.BCrypt.BCRYPT_CHAIN_MODE_CBC + "\0"), CngPropertyOptions.None);
     }
 }
index abd62a6..981242f 100644 (file)
@@ -11,7 +11,6 @@ namespace System.Security.Cryptography.Cng.Tests
 
         private static readonly CngAlgorithm s_cngAlgorithm = new CngAlgorithm("AES");
 
-        [ActiveIssue("https://github.com/dotnet/runtime/issues/31092")]
         [OuterLoop(/* Creates/Deletes a persisted key, limit exposure to key leaking */)]
         [ConditionalTheory(nameof(SupportsPersistedSymmetricKeys))]
         // AES128-ECB-NoPadding 2 blocks.
@@ -48,7 +47,6 @@ namespace System.Security.Cryptography.Cng.Tests
                 keyName => new AesCng(keyName));
         }
 
-        [ActiveIssue("https://github.com/dotnet/runtime/issues/31092")]
         [OuterLoop(/* Creates/Deletes a persisted key, limit exposure to key leaking */)]
         [ConditionalFact(nameof(SupportsPersistedSymmetricKeys))]
         public static void SetKey_DetachesFromPersistedKey()
@@ -75,7 +73,6 @@ namespace System.Security.Cryptography.Cng.Tests
             }
         }
 
-        [ActiveIssue("https://github.com/dotnet/runtime/issues/31092")]
         [OuterLoop(/* Creates/Deletes a persisted key, limit exposure to key leaking */)]
         [ConditionalFact(nameof(SupportsPersistedSymmetricKeys), nameof(IsAdministrator))]
         public static void VerifyMachineKey()
index 6abee43..60934e5 100644 (file)
@@ -11,7 +11,6 @@ namespace System.Security.Cryptography.Cng.Tests
 
         private static readonly CngAlgorithm s_cngAlgorithm = new CngAlgorithm("3DES");
 
-        [ActiveIssue("https://github.com/dotnet/runtime/issues/31092")]
         [OuterLoop(/* Creates/Deletes a persisted key, limit exposure to key leaking */)]
         [ConditionalTheory(nameof(SupportsPersistedSymmetricKeys))]
         // 3DES192-ECB-NoPadding 2 blocks.
@@ -46,7 +45,6 @@ namespace System.Security.Cryptography.Cng.Tests
                 keyName => new TripleDESCng(keyName));
         }
 
-        [ActiveIssue("https://github.com/dotnet/runtime/issues/31092")]
         [OuterLoop(/* Creates/Deletes a persisted key, limit exposure to key leaking */)]
         [ConditionalFact(nameof(SupportsPersistedSymmetricKeys))]
         public static void SetKey_DetachesFromPersistedKey()
@@ -73,7 +71,6 @@ namespace System.Security.Cryptography.Cng.Tests
             }
         }
 
-        [ActiveIssue("https://github.com/dotnet/runtime/issues/31092")]
         [OuterLoop(/* Creates/Deletes a persisted key, limit exposure to key leaking */)]
         [ConditionalFact(nameof(SupportsPersistedSymmetricKeys), nameof(IsAdministrator))]
         public static void VerifyMachineKey()