예제 #1
0
        /// <summary>
        /// Instantiate a thumb print
        /// </summary>
        /// <param name="key">The key to thumbprint.</param>
        /// <param name="salt">The salt to use.</param>
        public AesKeyThumbprint(AesKey key, KeyWrapSalt salt, long iterations)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            if (salt == null)
            {
                throw new ArgumentNullException("salt");
            }

            KeyWrap keyWrap = new KeyWrap(key, salt, iterations, KeyWrapMode.Specification);

            byte[] wrap = keyWrap.Wrap(key);

            Initialize(wrap);
        }
예제 #2
0
        public static void TestDispose()
        {
            KeyWrap keyWrap = new KeyWrap(_keyEncryptingKey, 6, KeyWrapMode.Specification);
            keyWrap.Dispose();
            Assert.Throws<ObjectDisposedException>(() =>
            {
                keyWrap.Wrap(new AesKey());
            });

            Assert.Throws<ObjectDisposedException>(() =>
            {
                keyWrap.Unwrap(new byte[16 + 8]);
            });

            Assert.DoesNotThrow(() =>
            {
                keyWrap.Dispose();
            });
        }
        /// <summary>
        /// Instantiate a thumb print
        /// </summary>
        /// <param name="passphrase">The passphrase to thumbprint.</param>
        /// <param name="salt">The salt to use.</param>
        public SymmetricKeyThumbprint(Passphrase passphrase, Salt salt, long keyWrapIterations)
        {
            if (passphrase == null)
            {
                throw new ArgumentNullException("passphrase");
            }
            if (salt == null)
            {
                throw new ArgumentNullException("salt");
            }

            ICryptoFactory factory = Resolve.CryptoFactory.Minimum;
            ICrypto        crypto  = factory.CreateCrypto(factory.RestoreDerivedKey(passphrase, salt, CryptoFactory.DerivationIterations).DerivedKey, null, 0);
            KeyWrap        keyWrap = new KeyWrap(salt, keyWrapIterations, KeyWrapMode.Specification);

            byte[] wrap = keyWrap.Wrap(crypto, crypto.Key);

            _bytes = wrap.Reduce(6);
        }
예제 #4
0
 public void RewrapMasterKey(AesKey masterKey, AesKey keyEncryptingKey)
 {
     KeyWrapSalt salt = new KeyWrapSalt(keyEncryptingKey.Length);
     using (KeyWrap keyWrap = new KeyWrap(keyEncryptingKey, salt, Iterations, KeyWrapMode.AxCrypt))
     {
         byte[] wrappedKeyData = keyWrap.Wrap(masterKey);
         Set(wrappedKeyData, salt, Iterations);
     }
 }
예제 #5
0
 private void Initialize(AesKey keyEncryptingKey)
 {
     AesKey masterKey = new AesKey();
     long iterations = OS.Current.KeyWrapIterations;
     KeyWrapSalt salt = new KeyWrapSalt(keyEncryptingKey.Length);
     using (KeyWrap keyWrap = new KeyWrap(keyEncryptingKey, salt, iterations, KeyWrapMode.AxCrypt))
     {
         byte[] wrappedKeyData = keyWrap.Wrap(masterKey);
         Set(wrappedKeyData, salt, iterations);
     }
 }
예제 #6
0
        public void TestWrapAndUnwrapSpecificationMode()
        {
            AesKey keyToWrap = new AesKey(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 });
            AesKey keyEncryptingKey = new AesKey(new byte[] { 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 });
            KeyWrapSalt salt = new KeyWrapSalt(new byte[] { 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 });
            long iterations = 23456;
            byte[] wrapped;
            using (KeyWrap keyWrap = new KeyWrap(keyEncryptingKey, salt, iterations, KeyWrapMode.Specification))
            {
                wrapped = keyWrap.Wrap(keyToWrap);
            }
            byte[] unwrapped;
            using (KeyWrap keyWrap = new KeyWrap(keyEncryptingKey, salt, iterations, KeyWrapMode.Specification))
            {
                unwrapped = keyWrap.Unwrap(wrapped);
            }

            Assert.That(unwrapped, Is.EquivalentTo(keyToWrap.GetBytes()), "The unwrapped data should be equal to original.");
        }
예제 #7
0
        public void TestWrap()
        {
            byte[] wrapped;
            using (KeyWrap keyWrap = new KeyWrap(_keyEncryptingKey, 6, KeyWrapMode.Specification))
            {
                wrapped = keyWrap.Wrap(_keyData);
            }

            Assert.That(wrapped, Is.EquivalentTo(_wrapped), "The wrapped data is not correct according to specification.");

            using (KeyWrap keyWrap = new KeyWrap(_keyEncryptingKey, 6, KeyWrapMode.Specification))
            {
                Assert.Throws<ArgumentNullException>(() =>
                {
                    wrapped = keyWrap.Wrap(null);
                });
            }
        }
            public void Iterate(long keyWrapIterations)
            {
                KeyWrap keyWrap = new KeyWrap(_dummySalt, keyWrapIterations, KeyWrapMode.Specification);

                keyWrap.Wrap(_dummyCrypto, _dummyKey);
            }