コード例 #1
0
        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);
        }
コード例 #2
0
        public void UnwrapKey()
        {
            var provider = new DerivedRsaKeyWrapProvider(KeyingMaterial.RsaSecurityKey_2048, SecurityAlgorithms.RsaPKCS1, true);
            var keyBytes = provider.WrapKey(Guid.NewGuid().ToByteArray());

            provider.UnwrapKey(keyBytes);
            Assert.True(provider.UnwrapKeyCalled);
            Assert.True(provider.WrapKeyCalled);
        }
コード例 #3
0
        public void RsaWrapUnwrapKey(RsaKeyWrapTestParams theoryParams)
        {
            try
            {
                var    encryptProvider = new RsaKeyWrapProvider(theoryParams.EncryptKey, theoryParams.EncryptAlgorithm, false);
                var    wrappedKey      = encryptProvider.WrapKey(theoryParams.KeyToWrap);
                var    decryptProvider = new DerivedRsaKeyWrapProvider(theoryParams.DecryptKey, theoryParams.DecryptAlgorithm, true);
                byte[] unwrappedKey    = decryptProvider.UnwrapKey(wrappedKey);

                Assert.True(Utility.AreEqual(unwrappedKey, theoryParams.KeyToWrap), "theoryParams.KeyToWrap != unwrappedKey");

                theoryParams.EE.ProcessNoException();
            }
            catch (Exception ex)
            {
                theoryParams.EE.ProcessException(ex);
            }
        }