コード例 #1
0
        /// <summary>
        /// <para>Decrypts bytes with the initialized algorithm and key.</para>
        /// </summary>
        /// <param name="encryptedText"><para>The text which you wish to decrypt.</para></param>
        /// <returns><para>The resulting plaintext.</para></returns>
        public virtual byte[] Decrypt(byte[] encryptedText)
        {
            byte[] output = null;
            byte[] data   = this.ExtractIV(encryptedText);

            this.algorithm.Key = Key;

            using (ICryptoTransform transform = this.algorithm.CreateDecryptor())
            {
                //output = this.Transform(transform, data);
                output = CryptographyUtility.Transform(transform, data);
            }

            CryptographyUtility.ZeroOutBytes(this.algorithm.Key);

            return(output);
        }
コード例 #2
0
        /// <summary>
        /// <para>Encrypts bytes with the initialized algorithm and key.</para>
        /// </summary>
        /// <param name="plaintext"><para>The plaintext in which you wish to encrypt.</para></param>
        /// <returns><para>The resulting ciphertext.</para></returns>
        public virtual byte[] Encrypt(byte[] plaintext)
        {
            byte[] output     = null;
            byte[] cipherText = null;

            this.algorithm.Key = Key;

            using (ICryptoTransform transform = this.algorithm.CreateEncryptor())
            {
                //cipherText = this.Transform(transform, plaintext);
                cipherText = CryptographyUtility.Transform(transform, plaintext);
            }

            output = new byte[IVLength + cipherText.Length];
            Buffer.BlockCopy(this.algorithm.IV, 0, output, 0, IVLength);
            Buffer.BlockCopy(cipherText, 0, output, IVLength, cipherText.Length);

            CryptographyUtility.ZeroOutBytes(this.algorithm.Key);

            return(output);
        }