Beispiel #1
0
        /// <summary>
        /// 加密
        /// </summary>
        /// <param name="plainText">明文</param>
        /// <param name="encryptKey">加密密钥</param>
        /// <returns></returns>
        public string Encrypt(string plainText, string encryptKey)
        {
            if (!string.IsNullOrEmpty(encryptKey))
            {
                this.key    = encryptKey;
                mCrypto.Key = GetLegalKey();
            }

            byte[] arrPlainText = Encoding.UTF8.GetBytes(plainText);
            using (MemoryStream stream = new MemoryStream())
            {
                ICryptoTransform encryptor = mCrypto.CreateEncryptor();
                using (CryptoStream cStream = new CryptoStream(stream, encryptor, CryptoStreamMode.Write))
                {
                    cStream.Write(arrPlainText, 0, arrPlainText.Length);
                    cStream.FlushFinalBlock();
                }
                byte[] outputBytes = stream.ToArray();
                return(Convert.ToBase64String(outputBytes));
            }
        }
Beispiel #2
0
 public override ICryptoTransform CreateEncryptor() => _impl.CreateEncryptor();