diff --git a/eng/liveBuilds.targets b/eng/liveBuilds.targets
index 5802882a82a0b0..5a3bf10c3e00ac 100644
--- a/eng/liveBuilds.targets
+++ b/eng/liveBuilds.targets
@@ -179,7 +179,6 @@
-
@@ -220,7 +219,6 @@
-
diff --git a/src/libraries/Common/src/Interop/Browser/Interop.Libraries.cs b/src/libraries/Common/src/Interop/Browser/Interop.Libraries.cs
index b28d723f0bfc9d..df7bdb4b890559 100644
--- a/src/libraries/Common/src/Interop/Browser/Interop.Libraries.cs
+++ b/src/libraries/Common/src/Interop/Browser/Interop.Libraries.cs
@@ -7,6 +7,5 @@ internal static partial class Libraries
{
// Shims
internal const string SystemNative = "libSystem.Native";
- internal const string CryptoNative = "libSystem.Security.Cryptography.Native.Browser";
}
}
diff --git a/src/libraries/Common/src/Interop/Browser/System.Security.Cryptography.Native.Browser/Interop.SubtleCrypto.cs b/src/libraries/Common/src/Interop/Browser/System.Security.Cryptography.Native.Browser/Interop.SubtleCrypto.cs
deleted file mode 100644
index 1e6ea5c2821faa..00000000000000
--- a/src/libraries/Common/src/Interop/Browser/System.Security.Cryptography.Native.Browser/Interop.SubtleCrypto.cs
+++ /dev/null
@@ -1,67 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class BrowserCrypto
- {
- // These values are also defined in the pal_crypto_webworker header file, and utilized in the dotnet-crypto-worker in the wasm runtime.
- internal enum SimpleDigest
- {
- Sha1,
- Sha256,
- Sha384,
- Sha512,
- };
-
- internal static readonly bool CanUseSubtleCrypto = CanUseSubtleCryptoImpl() == 1;
-
- [LibraryImport(Libraries.CryptoNative, EntryPoint = "SystemCryptoNativeBrowser_CanUseSubtleCryptoImpl")]
- private static partial int CanUseSubtleCryptoImpl();
-
- [LibraryImport(Libraries.CryptoNative, EntryPoint = "SystemCryptoNativeBrowser_SimpleDigestHash")]
- internal static unsafe partial int SimpleDigestHash(
- SimpleDigest hash,
- byte* input_buffer,
- int input_len,
- byte* output_buffer,
- int output_len);
-
- [LibraryImport(Libraries.CryptoNative, EntryPoint = "SystemCryptoNativeBrowser_Sign")]
- internal static unsafe partial int Sign(
- SimpleDigest hashAlgorithm,
- byte* key_buffer,
- int key_len,
- byte* input_buffer,
- int input_len,
- byte* output_buffer,
- int output_len);
-
- [LibraryImport(Libraries.CryptoNative, EntryPoint = "SystemCryptoNativeBrowser_EncryptDecrypt")]
- internal static unsafe partial int EncryptDecrypt(
- int encrypting,
- byte* key_buffer,
- int key_len,
- byte* iv_buffer,
- int iv_len,
- byte* input_buffer,
- int input_len,
- byte* output_buffer,
- int output_len);
-
- [LibraryImport(Libraries.CryptoNative, EntryPoint = "SystemCryptoNativeBrowser_DeriveBits")]
- internal static unsafe partial int DeriveBits(
- byte* password_buffer,
- int password_len,
- byte* salt_buffer,
- int salt_len,
- int iterations,
- SimpleDigest hashAlgorithm,
- byte* output_buffer,
- int output_len);
- }
-}
diff --git a/src/libraries/Common/src/System/Security/Cryptography/Helpers.cs b/src/libraries/Common/src/System/Security/Cryptography/Helpers.cs
index 685a7e1beed628..b1dc4d1de9a04c 100644
--- a/src/libraries/Common/src/System/Security/Cryptography/Helpers.cs
+++ b/src/libraries/Common/src/System/Security/Cryptography/Helpers.cs
@@ -11,7 +11,7 @@ namespace Internal.Cryptography
internal static partial class Helpers
{
[UnsupportedOSPlatformGuard("browser")]
- internal static bool HasNonAesSymmetricEncryption =>
+ internal static bool HasSymmetricEncryption { get; } =
#if NETCOREAPP
!OperatingSystem.IsBrowser();
#else
diff --git a/src/libraries/Common/src/System/Security/Cryptography/PasswordBasedEncryption.cs b/src/libraries/Common/src/System/Security/Cryptography/PasswordBasedEncryption.cs
index 185eb3fcf2b6b7..800b4f335e892c 100644
--- a/src/libraries/Common/src/System/Security/Cryptography/PasswordBasedEncryption.cs
+++ b/src/libraries/Common/src/System/Security/Cryptography/PasswordBasedEncryption.cs
@@ -74,20 +74,7 @@ internal static unsafe int Decrypt(
{
Debug.Assert(destination.Length >= encryptedData.Length);
- // Don't check that algorithmIdentifier.Parameters is set here.
- // Maybe some future PBES3 will have one with a default.
-
- if (algorithmIdentifier.Algorithm == Oids.PasswordBasedEncryptionScheme2)
- {
- return Pbes2Decrypt(
- algorithmIdentifier.Parameters,
- password,
- passwordBytes,
- encryptedData,
- destination);
- }
-
- if (!Helpers.HasNonAesSymmetricEncryption)
+ if (!Helpers.HasSymmetricEncryption)
{
throw new CryptographicException(
SR.Format(
@@ -95,8 +82,11 @@ internal static unsafe int Decrypt(
algorithmIdentifier.Algorithm));
}
+ // Don't check that algorithmIdentifier.Parameters is set here.
+ // Maybe some future PBES3 will have one with a default.
+
HashAlgorithmName digestAlgorithmName;
- SymmetricAlgorithm cipher;
+ SymmetricAlgorithm? cipher = null;
bool pkcs12 = false;
@@ -141,6 +131,13 @@ internal static unsafe int Decrypt(
cipher.KeySize = 40;
pkcs12 = true;
break;
+ case Oids.PasswordBasedEncryptionScheme2:
+ return Pbes2Decrypt(
+ algorithmIdentifier.Parameters,
+ password,
+ passwordBytes,
+ encryptedData,
+ destination);
default:
throw new CryptographicException(
SR.Format(
@@ -149,6 +146,7 @@ internal static unsafe int Decrypt(
}
Debug.Assert(digestAlgorithmName.Name != null);
+ Debug.Assert(cipher != null);
using (cipher)
{
@@ -239,6 +237,14 @@ internal static void InitiateEncryption(
{
Debug.Assert(pbeParameters != null);
+ if (!Helpers.HasSymmetricEncryption)
+ {
+ throw new CryptographicException(
+ SR.Format(
+ SR.Cryptography_UnknownAlgorithmIdentifier,
+ pbeParameters.EncryptionAlgorithm));
+ }
+
isPkcs12 = false;
switch (pbeParameters.EncryptionAlgorithm)
@@ -258,7 +264,7 @@ internal static void InitiateEncryption(
cipher.KeySize = 256;
encryptionAlgorithmOid = Oids.Aes256Cbc;
break;
- case PbeEncryptionAlgorithm.TripleDes3KeyPkcs12 when Helpers.HasNonAesSymmetricEncryption:
+ case PbeEncryptionAlgorithm.TripleDes3KeyPkcs12:
cipher = TripleDES.Create();
cipher.KeySize = 192;
encryptionAlgorithmOid = Oids.Pkcs12PbeWithShaAnd3Key3Des;
@@ -566,6 +572,12 @@ private static SymmetricAlgorithm OpenCipher(
{
string? algId = encryptionScheme.Algorithm;
+ if (!Helpers.HasSymmetricEncryption)
+ {
+ throw new CryptographicException(
+ SR.Format(SR.Cryptography_AlgorithmNotSupported, algId));
+ }
+
if (algId == Oids.Aes128Cbc ||
algId == Oids.Aes192Cbc ||
algId == Oids.Aes256Cbc)
@@ -604,12 +616,6 @@ private static SymmetricAlgorithm OpenCipher(
return aes;
}
- if (!Helpers.HasNonAesSymmetricEncryption)
- {
- throw new CryptographicException(
- SR.Format(SR.Cryptography_AlgorithmNotSupported, algId));
- }
-
if (algId == Oids.TripleDesCbc)
{
// https://tools.ietf.org/html/rfc8018#appendix-B.2.2
diff --git a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/AesCipherOneShotTests.cs b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/AesCipherOneShotTests.cs
index ec1a58e1ada7c3..c489db5197333f 100644
--- a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/AesCipherOneShotTests.cs
+++ b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/AesCipherOneShotTests.cs
@@ -9,6 +9,7 @@
namespace System.Security.Cryptography.Encryption.Aes.Tests
{
+ [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")]
public class AesCipherOneShotTests : SymmetricOneShotBase
{
protected override byte[] Key =>
@@ -414,251 +415,519 @@ public static IEnumerable