コード例 #1
0
        /// <summary>Initializes a new instance of the <see cref="T:System.Security.Cryptography.Rfc2898DeriveBytes" /> class using a password, a salt, and number of iterations to derive the key.</summary>
        /// <param name="password">The password used to derive the key. </param>
        /// <param name="salt">The key salt used to derive the key.</param>
        /// <param name="derivationIterations">The number of iterations for the operation. </param>
        /// <exception cref="T:System.ArgumentNullException">The password or salt is null. </exception>
        public Pbkdf2HmacSha512(string password, Salt salt, int derivationIterations)
        {
            if (password == null)
            {
                throw new ArgumentNullException("password");
            }
            if (salt == null)
            {
                throw new ArgumentNullException("salt");
            }
            if (derivationIterations <= 0)
            {
                throw new ArgumentOutOfRangeException("derivationIterations", "Must be greater than 0.");
            }

            _bytes = F(password, salt, derivationIterations);
        }
コード例 #2
0
 /// <summary>
 /// Create a KeyWrap instance for wrapping or unwrapping
 /// </summary>
 /// <param name="salt">A salt. This is required by AxCrypt, although the algorithm supports not using a salt.</param>
 /// <param name="keyWrapIterations">The number of wrapping iterations, at least 6</param>
 /// <param name="mode">Use original specification mode or AxCrypt mode (only difference is that 't' is little endian in AxCrypt mode)</param>
 public KeyWrap(Salt salt, long keyWrapIterations, KeyWrapMode mode)
 {
     if (salt == null)
     {
         throw new ArgumentNullException("salt");
     }
     if (keyWrapIterations < 6)
     {
         throw new InternalErrorException("Key wrap iterations must be at least 6.");
     }
     if (mode != KeyWrapMode.Specification && mode != KeyWrapMode.AxCrypt)
     {
         throw new InternalErrorException("mode");
     }
     _salt = salt;
     _mode = mode;
     _keyWrapIterations = keyWrapIterations;
 }
コード例 #3
0
        /// <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 IDerivedKey RestoreDerivedKey(Passphrase passphrase, Salt salt, int derivationIterations)
 {
     return(new V2DerivedKey(passphrase, salt, derivationIterations, 128));
 }
コード例 #5
0
 /// <summary>
 /// Create an instance of tranform suitable for NIST Key Wrap
 /// </summary>
 /// <returns></returns>
 /// <value>
 /// An instance of the algorithm.
 /// </value>
 public override IKeyWrapTransform CreateKeyWrapTransform(Salt salt, KeyWrapDirection keyWrapDirection)
 {
     return(new BlockAlgorithmKeyWrapTransform(CreateAlgorithmInternal(), salt, keyWrapDirection));
 }
コード例 #6
0
 /// <summary>
 /// Create an instance of a transform suitable for NIST Key Wrap.
 /// </summary>
 /// <param name="salt"></param>
 /// <param name="keyWrapDirection"></param>
 /// <returns></returns>
 /// <value>
 /// An instance of the transform.
 ///   </value>
 public abstract IKeyWrapTransform CreateKeyWrapTransform(Salt salt, KeyWrapDirection keyWrapDirection);