Esempio n. 1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="algorithm"></param>
        /// <param name="key"></param>
        public SymmetricEncryptor(SymmetricAlgorithm algorithm, string key)
        {
            algorithm.ShouldNotBeNull("algorithm");
            key.ShouldNotBeEmpty("key");

            //if(algorithm.GetType().Equals(typeof(RijndaelManaged)))
            //    throw new NotSupportedException("RijndaelManaged 알고리즘은 지원하지 않습니다. TripleDESCryptoServiceProvider를 사용하시기 바랍니다.");

            Algorithm = algorithm;
            Key       = key;

            var newLength = Algorithm.KeySize / 8;

            Algorithm.Key = CryptoTool.DerivePassword(Key, newLength);

            if (algorithm is Rijndael)
            {
                Algorithm.BlockSize = Algorithm.KeySize;
            }


            if (IsDebugEnabled)
            {
                log.Debug("대칭형 암호화를 수행하는 SymmectricEncryptor를 생성했습니다. Algorithm=[{0}], KeySize=[{1}], BlockSize=[{2}]",
                          Algorithm, Algorithm.KeySize, Algorithm.BlockSize);
            }
        }