public void RsaWrapUnwrapKey(KeyWrapTheoryData theoryData) { var context = TestUtilities.WriteHeader($"{this}.RsaWrapUnwrapKey", theoryData); try { var encryptProvider = new RsaKeyWrapProvider(theoryData.WrapKey, theoryData.WrapAlgorithm, false); var wrappedKey = encryptProvider.WrapKey(theoryData.KeyToWrap); var decryptProvider = new DerivedRsaKeyWrapProvider(theoryData.UnwrapKey, theoryData.UnwrapAlgorithm, true); byte[] unwrappedKey = decryptProvider.UnwrapKey(wrappedKey); if (!Utility.AreEqual(unwrappedKey, theoryData.KeyToWrap)) { context.AddDiff("theoryParams.KeyToWrap != unwrappedKey"); } theoryData.ExpectedException.ProcessNoException(context); } catch (Exception ex) { theoryData.ExpectedException.ProcessException(ex, context); } TestUtilities.AssertFailIfErrors(context); }
public void Constructors(KeyWrapTheoryData theoryData) { var context = TestUtilities.WriteHeader($"{this}.Constructors", theoryData); try { RsaKeyWrapProvider provider = null; var keyWrapContext = Guid.NewGuid().ToString(); if (theoryData.WillUnwrap) { provider = new RsaKeyWrapProvider(theoryData.UnwrapKey, theoryData.UnwrapAlgorithm, theoryData.WillUnwrap) { Context = keyWrapContext }; provider.CreateAsymmetricAdapter(); if (!provider.Algorithm.Equals(theoryData.UnwrapAlgorithm)) { context.AddDiff($"provider.Algorithm != theoryData.UnwrapAlgorithm: {provider.Algorithm} : {theoryData.UnwrapAlgorithm}."); } if (!ReferenceEquals(provider.Key, theoryData.UnwrapKey)) { context.AddDiff($"!ReferenceEquals(provider.key, theoryData.UnwrapKey)"); } } else { provider = new RsaKeyWrapProvider(theoryData.WrapKey, theoryData.WrapAlgorithm, theoryData.WillUnwrap) { Context = keyWrapContext }; provider.WrapKey(Guid.NewGuid().ToByteArray()); if (!provider.Algorithm.Equals(theoryData.WrapAlgorithm)) { context.AddDiff($"provider.Algorithm != theoryData.WrapAlgorithm: {provider.Algorithm} : {theoryData.WrapAlgorithm}."); } if (!ReferenceEquals(provider.Key, theoryData.WrapKey)) { context.AddDiff($"!ReferenceEquals(provider.key, theoryData.WrapKey)"); } } theoryData.ExpectedException.ProcessNoException(context); if (!provider.Context.Equals(keyWrapContext)) { context.AddDiff($"provider.Context != keyWrapContext: {provider.Context} : {keyWrapContext}."); } } catch (Exception ex) { theoryData.ExpectedException.ProcessException(ex, context); } TestUtilities.AssertFailIfErrors(context); }
public void UnwrapTamperedData(KeyWrapTheoryData theoryData) { var context = TestUtilities.WriteHeader($"{this}.UnwrapTamperedData", theoryData); try { theoryData.Provider.UnwrapKey(theoryData.WrappedKey); theoryData.ExpectedException.ProcessNoException(context); } catch (Exception ex) { theoryData.ExpectedException.ProcessException(ex, context); } TestUtilities.AssertFailIfErrors(context); }
public void UnwrapParameterCheck(KeyWrapTheoryData theoryData) { var context = TestUtilities.WriteHeader($"{this}.UnwrapParameterCheck", theoryData); try { var provider = CryptoProviderFactory.Default.CreateKeyWrapProvider(theoryData.WrapKey, theoryData.WrapAlgorithm); byte[] unwrappedKey = provider.UnwrapKey(theoryData.WrappedKey); theoryData.ExpectedException.ProcessNoException(context); } catch (Exception ex) { theoryData.ExpectedException.ProcessException(ex, context); } TestUtilities.AssertFailIfErrors(context); }
public void RsaUnwrapParameterCheck(KeyWrapTheoryData theoryData) { var context = TestUtilities.WriteHeader($"{this}.RsaUnwrapParameterCheck", theoryData); try { var provider = new RsaKeyWrapProvider(theoryData.UnwrapKey, theoryData.UnwrapAlgorithm, true); provider.UnwrapKey(theoryData.WrappedKey); theoryData.ExpectedException.ProcessNoException(context); } catch (Exception ex) { theoryData.ExpectedException.ProcessException(ex, context); } TestUtilities.AssertFailIfErrors(context); }
public void UnwrapMismatch(KeyWrapTheoryData theoryData) { var context = TestUtilities.WriteHeader($"{this}.UnwrapMismatch", theoryData); try { var encryptProvider = CryptoProviderFactory.Default.CreateKeyWrapProvider(theoryData.WrapKey, theoryData.WrapAlgorithm); byte[] keyToWrap = Guid.NewGuid().ToByteArray(); var wrappedKey = encryptProvider.WrapKey(keyToWrap); var decryptProvider = CryptoProviderFactory.Default.CreateKeyWrapProvider(theoryData.UnwrapKey, theoryData.UnwrapAlgorithm); byte[] unwrappedKey = decryptProvider.UnwrapKey(wrappedKey); theoryData.ExpectedException.ProcessNoException(context); } catch (Exception ex) { theoryData.ExpectedException.ProcessException(ex, context); } TestUtilities.AssertFailIfErrors(context); }
public void RsaUnwrapMismatch(KeyWrapTheoryData theoryData) { var context = TestUtilities.WriteHeader($"{this}.RsaUnwrapParameterCheck", theoryData); try { var encryptProvider = new RsaKeyWrapProvider(theoryData.WrapKey, theoryData.WrapAlgorithm, false); byte[] keyToWrap = Guid.NewGuid().ToByteArray(); var wrappedKey = encryptProvider.WrapKey(keyToWrap); var decryptProvider = new RsaKeyWrapProvider(theoryData.UnwrapKey, theoryData.UnwrapAlgorithm, true); byte[] unwrappedKey = decryptProvider.UnwrapKey(wrappedKey); theoryData.ExpectedException.ProcessNoException(context); } catch (Exception ex) { theoryData.ExpectedException.ProcessException(ex, context); } TestUtilities.AssertFailIfErrors(context); }
public void WrapUnwrapKey(KeyWrapTheoryData theoryData) { var context = TestUtilities.WriteHeader($"{this}.WrapUnwrapKey", theoryData); try { var provider = CryptoProviderFactory.Default.CreateKeyWrapProvider(theoryData.WrapKey, theoryData.WrapAlgorithm); var wrappedKey = provider.WrapKey(theoryData.KeyToWrap); byte[] unwrappedKey = provider.UnwrapKey(wrappedKey); Assert.True(Utility.AreEqual(unwrappedKey, theoryData.KeyToWrap), "theoryParams.KeyToWrap != unwrappedKey"); theoryData.ExpectedException.ProcessNoException(context); } catch (Exception ex) { theoryData.ExpectedException.ProcessException(ex, context); } TestUtilities.AssertFailIfErrors(context); }