Пример #1
0
        public static void AesThrows_PlatformNotSupported_CipherMode_Browser()
        {
            using (Aes aes = Aes.Create())
            {
                Assert.Throws <PlatformNotSupportedException>(() => aes.EncryptEcb(s_plainText, PaddingMode.PKCS7));
                Assert.Throws <PlatformNotSupportedException>(() => aes.EncryptEcb(s_plainText.AsSpan(), PaddingMode.PKCS7));
                Assert.Throws <PlatformNotSupportedException>(() => aes.EncryptEcb(s_plainText.AsSpan(), s_destination, PaddingMode.PKCS7));
                Assert.Throws <PlatformNotSupportedException>(() => aes.DecryptEcb(s_plainText, PaddingMode.PKCS7));
                Assert.Throws <PlatformNotSupportedException>(() => aes.DecryptEcb(s_plainText.AsSpan(), PaddingMode.PKCS7));
                Assert.Throws <PlatformNotSupportedException>(() => aes.DecryptEcb(s_plainText.AsSpan(), s_destination, PaddingMode.PKCS7));

                Assert.Throws <PlatformNotSupportedException>(() => aes.EncryptCfb(s_plainText, s_iv));
                Assert.Throws <PlatformNotSupportedException>(() => aes.EncryptCfb(s_plainText.AsSpan(), s_iv.AsSpan()));
                Assert.Throws <PlatformNotSupportedException>(() => aes.EncryptCfb(s_plainText.AsSpan(), s_iv, s_destination));
                Assert.Throws <PlatformNotSupportedException>(() => aes.DecryptCfb(s_plainText, s_iv));
                Assert.Throws <PlatformNotSupportedException>(() => aes.DecryptCfb(s_plainText.AsSpan(), s_iv.AsSpan()));
                Assert.Throws <PlatformNotSupportedException>(() => aes.DecryptCfb(s_plainText.AsSpan(), s_iv, s_destination));

                aes.Mode = CipherMode.ECB;
                Assert.Throws <PlatformNotSupportedException>(() => aes.CreateEncryptor());
                Assert.Throws <PlatformNotSupportedException>(() => aes.CreateEncryptor(s_iv, s_iv));
                Assert.Throws <PlatformNotSupportedException>(() => aes.CreateDecryptor());
                Assert.Throws <PlatformNotSupportedException>(() => aes.CreateDecryptor(s_iv, s_iv));

                aes.Mode = CipherMode.CFB;
                Assert.Throws <PlatformNotSupportedException>(() => aes.CreateEncryptor());
                Assert.Throws <PlatformNotSupportedException>(() => aes.CreateEncryptor(s_iv, s_iv));
                Assert.Throws <PlatformNotSupportedException>(() => aes.CreateDecryptor());
                Assert.Throws <PlatformNotSupportedException>(() => aes.CreateDecryptor(s_iv, s_iv));
            }
        }