public static TheoryData <string, SecurityKey, string, ExpectedException> KeyWrapConstructorTheoryData() { var theoryData = new TheoryData <string, SecurityKey, string, ExpectedException>(); theoryData.Add("Test1", null, null, ExpectedException.ArgumentNullException()); theoryData.Add("Test2", Default.SymmetricEncryptionKey128, null, ExpectedException.ArgumentNullException()); theoryData.Add("Test3", Default.SymmetricEncryptionKey128, SecurityAlgorithms.Aes128Encryption, ExpectedException.NotSupportedException("IDX10661:")); theoryData.Add("Test4", Default.SymmetricEncryptionKey128, SecurityAlgorithms.Aes128KW, ExpectedException.NoExceptionExpected); theoryData.Add("Test5", Default.SymmetricEncryptionKey256, SecurityAlgorithms.Aes256KW, ExpectedException.NoExceptionExpected); theoryData.Add("Test6", Default.SymmetricEncryptionKey128, SecurityAlgorithms.Aes256KW, ExpectedException.ArgumentOutOfRangeException("IDX10662:")); theoryData.Add("Test7", Default.SymmetricEncryptionKey256, SecurityAlgorithms.Aes128KW, ExpectedException.ArgumentOutOfRangeException("IDX10662:")); JsonWebKey key = new JsonWebKey() { Kty = JsonWebAlgorithmsKeyTypes.Octet }; theoryData.Add("Test8", key, SecurityAlgorithms.Aes256KW, ExpectedException.NotSupportedException("IDX10661:")); key = new JsonWebKey() { Kty = JsonWebAlgorithmsKeyTypes.RSA, K = KeyingMaterial.JsonWebKeySymmetric128.K }; theoryData.Add("Test9", key, SecurityAlgorithms.Aes256KW, ExpectedException.NotSupportedException("IDX10661:")); theoryData.Add("Test10", KeyingMaterial.RsaSecurityKey_2048, SecurityAlgorithms.Aes256KW, ExpectedException.NotSupportedException("IDX10661:")); theoryData.Add("Test11", KeyingMaterial.JsonWebKeySymmetric128, SecurityAlgorithms.Aes128KW, ExpectedException.NoExceptionExpected); theoryData.Add("Test12", KeyingMaterial.JsonWebKeySymmetric256, SecurityAlgorithms.Aes256KW, ExpectedException.NoExceptionExpected); return(theoryData); }
public void DefaultCryptoProviderFactoryGetHashAlgorithm(string algorithm, bool isSupported) { var ee = isSupported ? ExpectedException.NoExceptionExpected : ExpectedException.NotSupportedException("IDX10640:"); try { CryptoProviderFactory.Default.CreateHashAlgorithm(algorithm); ee.ProcessNoException(); } catch (Exception ex) { ee.ProcessException(ex); } }
public void UnsupportedRSATypes() { var context = new CompareContext("UnsupportedRSATypes"); TestUtilities.WriteHeader($"{this}.UnsupportedRSATypes"); #if NET452 var expectedException = ExpectedException.NotSupportedException(); #endif #if NET461 || NET_CORE var expectedException = ExpectedException.NoExceptionExpected; #endif try { new AsymmetricAdapter(new RsaSecurityKey(new DerivedRsa(2048)), SecurityAlgorithms.RsaSha256, false); expectedException.ProcessNoException(context); } catch (Exception ex) { expectedException.ProcessException(ex, context); } #if NET452 // RSA-PSS is not available on .NET 4.5.2 expectedException = ExpectedException.NotSupportedException("IDX10687:"); #endif #if NET461 || NET_CORE expectedException = ExpectedException.NoExceptionExpected; #endif try { new AsymmetricAdapter(new RsaSecurityKey(new DerivedRsa(2048)), SecurityAlgorithms.RsaSha256, false); expectedException.ProcessNoException(context); } catch (Exception ex) { expectedException.ProcessException(ex, context); } TestUtilities.AssertFailIfErrors(context); }
public void UnsupportedRSAType() { #if NET452 var expectedException = ExpectedException.NotSupportedException(); #endif #if NET461 || NETCOREAPP2_0 var expectedException = ExpectedException.NoExceptionExpected; #endif try { new AsymmetricSignatureProvider(new RsaSecurityKey(new DerivedRsa(2048)), SecurityAlgorithms.RsaSha256, false); expectedException.ProcessNoException(); } catch (Exception ex) { expectedException.ProcessException(ex); } }
public static TheoryData <string, SecurityKey, string, bool, ExpectedException> RsaKeyWrapConstructorTheoryData() { var theoryData = new TheoryData <string, SecurityKey, string, bool, ExpectedException>(); theoryData.Add( "SecurityKey_NULL", null, null, false, ExpectedException.ArgumentNullException()); theoryData.Add( "Algorithm_NULL", KeyingMaterial.RsaSecurityKey_2048, null, false, ExpectedException.ArgumentNullException()); theoryData.Add( "KeyTooSmall_1024", KeyingMaterial.RsaSecurityKey_1024, SecurityAlgorithms.RsaOAEP, false, ExpectedException.NotSupportedException("IDX10661:")); theoryData.Add( "KeyDoesNotRightType", KeyingMaterial.RsaSecurityKey_2048, SecurityAlgorithms.Aes128KW, false, ExpectedException.NotSupportedException("IDX10661:")); theoryData.Add( "KeyAlgorithmMatch", KeyingMaterial.RsaSecurityKey_2048, SecurityAlgorithms.RsaPKCS1, false, ExpectedException.NoExceptionExpected); theoryData.Add( "X509AlorithmMatch", KeyingMaterial.X509SecurityKey2, SecurityAlgorithms.RsaPKCS1, false, ExpectedException.NoExceptionExpected); theoryData.Add( "JWK_RSA", KeyingMaterial.JsonWebKeyRsa256, SecurityAlgorithms.RsaPKCS1, true, ExpectedException.NoExceptionExpected); theoryData.Add( "OnlyRSAPublicKeyProvided", KeyingMaterial.JsonWebKeyRsa256Public, SecurityAlgorithms.RsaPKCS1, true, ExpectedException.NoExceptionExpected); return(theoryData); }
public static TheoryData <KeyWrapTheoryData> RsaKeyWrapConstructorTheoryData() { return(new TheoryData <KeyWrapTheoryData> { new KeyWrapTheoryData { ExpectedException = ExpectedException.ArgumentNullException("key"), First = true, TestId = "SecurityKeyNULL", WillUnwrap = false, WrapAlgorithm = SecurityAlgorithms.Aes128KeyWrap, WrapKey = null }, new KeyWrapTheoryData { ExpectedException = ExpectedException.ArgumentNullException("algorithm"), TestId = "AlgorithmNULL", WillUnwrap = false, WrapAlgorithm = null, WrapKey = KeyingMaterial.RsaSecurityKey_2048 }, new KeyWrapTheoryData { ExpectedException = ExpectedException.NotSupportedException("IDX10661:"), TestId = "KeyTooSmall1024", WillUnwrap = false, WrapAlgorithm = SecurityAlgorithms.RsaOAEP, WrapKey = KeyingMaterial.RsaSecurityKey_1024 }, new KeyWrapTheoryData { ExpectedException = ExpectedException.NotSupportedException("IDX10661:"), TestId = "KeyDoesNotMatchAlgorithm", WillUnwrap = false, WrapAlgorithm = SecurityAlgorithms.Aes128KW, WrapKey = KeyingMaterial.RsaSecurityKey_2048 }, new KeyWrapTheoryData { TestId = "RsaAlgorithmMatch", WillUnwrap = false, WrapAlgorithm = SecurityAlgorithms.RsaPKCS1, WrapKey = KeyingMaterial.RsaSecurityKey_2048 }, new KeyWrapTheoryData { TestId = "X509AlgorithmMatch", WillUnwrap = false, WrapKey = KeyingMaterial.X509SecurityKey2, WrapAlgorithm = SecurityAlgorithms.RsaPKCS1 }, new KeyWrapTheoryData { TestId = "JwkRSA", WillUnwrap = false, WrapKey = KeyingMaterial.JsonWebKeyRsa256, WrapAlgorithm = SecurityAlgorithms.RsaPKCS1, }, new KeyWrapTheoryData { TestId = "RsaPublicKey", UnwrapKey = KeyingMaterial.JsonWebKeyRsa256Public, UnwrapAlgorithm = SecurityAlgorithms.RsaPKCS1, WillUnwrap = true } }); }