示例#1
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));
 }
        public BlockAlgorithmKeyWrapTransform(SymmetricAlgorithm symmetricAlgorithm, Salt salt, KeyWrapDirection keyWrapDirection)
        {
            if (symmetricAlgorithm == null)
            {
                throw new ArgumentNullException("symmetricAlgorithm");
            }
            if (salt == null)
            {
                throw new ArgumentNullException("salt");
            }

            if (salt.Length != 0 && salt.Length < symmetricAlgorithm.Key().Length)
            {
                throw new InternalErrorException("Salt is too short. It must be at least as long as the algorithm key, or empty for no salt.");
            }
            _algorithm = symmetricAlgorithm;

            byte[] saltedKey = _algorithm.Key();
            saltedKey.Xor(salt.GetBytes().Reduce(saltedKey.Length));
            _algorithm.SetKey(saltedKey);

            _algorithm.Mode    = CipherMode.ECB;
            _algorithm.Padding = PaddingMode.None;

            BlockLength = _algorithm.BlockSize / 8;

            _transform = keyWrapDirection == KeyWrapDirection.Encrypt ? _algorithm.CreateEncryptingTransform() : _algorithm.CreateDecryptingTransform();
        }
示例#3
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);