Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Subkey"/> class. Different data is encrypted using
        /// different variants of the master encryption key.
        /// </summary>
        /// <param name="masterKey">The master key.</param>
        /// <param name="headerSubkey">The header subkey.</param>
        public Subkey(AesKey masterKey, HeaderSubkey headerSubkey)
        {
            if (masterKey == null)
            {
                throw new ArgumentNullException("masterKey");
            }

            byte[] block = new byte[16];
            byte subKeyValue;
            switch (headerSubkey)
            {
                case HeaderSubkey.Hmac:
                    subKeyValue = 0;
                    break;
                case HeaderSubkey.Validator:
                    subKeyValue = 1;
                    break;
                case HeaderSubkey.Headers:
                    subKeyValue = 2;
                    break;
                case HeaderSubkey.Data:
                    subKeyValue = 3;
                    break;
                default:
                    throw new InternalErrorException("headerSubkey");
            }

            block[0] = subKeyValue;
            using (AesCrypto aesCrypto = new AesCrypto(masterKey))
            {
                _subKey = new AesKey(aesCrypto.Encrypt(block));
            }
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Subkey"/> class. Different data is encrypted using
        /// different variants of the master encryption key.
        /// </summary>
        /// <param name="masterKey">The master key.</param>
        /// <param name="headerSubkey">The header subkey.</param>
        public Subkey(SymmetricKey masterKey, HeaderSubkey headerSubkey)
        {
            if (masterKey == null)
            {
                throw new ArgumentNullException("masterKey");
            }

            byte[] block = new byte[16];
            byte   subKeyValue;

            switch (headerSubkey)
            {
            case HeaderSubkey.Hmac:
                subKeyValue = 0;
                break;

            case HeaderSubkey.Validator:
                subKeyValue = 1;
                break;

            case HeaderSubkey.Headers:
                subKeyValue = 2;
                break;

            case HeaderSubkey.Data:
                subKeyValue = 3;
                break;

            default:
                throw new InternalErrorException("Invalid header sub key.");
            }

            block[0] = subKeyValue;
            _subKey  = new SymmetricKey(Resolve.CryptoFactory.Legacy.CreateCrypto(masterKey, null, 0).Encrypt(block));
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Subkey"/> class. Different data is encrypted using
        /// different variants of the master encryption key.
        /// </summary>
        /// <param name="masterKey">The master key.</param>
        /// <param name="headerSubkey">The header subkey.</param>
        public Subkey(AesKey masterKey, HeaderSubkey headerSubkey)
        {
            if (masterKey == null)
            {
                throw new ArgumentNullException("masterKey");
            }

            byte[] block = new byte[16];
            byte   subKeyValue;

            switch (headerSubkey)
            {
            case HeaderSubkey.Hmac:
                subKeyValue = 0;
                break;

            case HeaderSubkey.Validator:
                subKeyValue = 1;
                break;

            case HeaderSubkey.Headers:
                subKeyValue = 2;
                break;

            case HeaderSubkey.Data:
                subKeyValue = 3;
                break;

            default:
                throw new InternalErrorException("headerSubkey");
            }

            block[0] = subKeyValue;
            using (AesCrypto aesCrypto = new AesCrypto(masterKey))
            {
                _subKey = new AesKey(aesCrypto.Encrypt(block));
            }
        }