Exemplo n.º 1
0
        /****************************************************************************/
        /// <summary>
        /// Generate a new key using the given policy
        /// </summary>
        /// <param name="policy">Policy to create key with</param>
        public Key(EncryptionPolicy policy)
        {
            _policy = policy;

            // Reset expiration date to original
            _policy.IsReadOnly = false;
            _policy.Expires    = policy.Expires;
            _policy.IsReadOnly = true;

            _keyBytes = SymmetricEncryptor.GenerateKey(_policy);
        }
Exemplo n.º 2
0
        /****************************************************************************/
        internal static byte[] GenerateKey(EncryptionPolicy policy)
        {
            using (var encryptor = new SymmetricEncryptor(policy))
            {
                using (var algorithm = encryptor.GetAlgorithm(policy))
                {
                    SetKeySize(algorithm, policy.KeySize);

                    policy.IsReadOnly = false;
                    policy.KeySize    = algorithm.KeySize;
                    policy.Algorithm  = algorithm.GetType().ToString();
                    policy.IsReadOnly = true;

                    algorithm.GenerateKey();

                    return(algorithm.Key.DeepClone());
                }
            }
        }