//加密字符串 public string Encryption(string toE) { //加密和解密必须采用相同的key,具体自己填写,但是必须为32位 byte[] keyArray = UTF8Encoding.UTF8.GetBytes("12345678123456781234567812345678"); RijndaelManaged rijndaelManaged = new RijndaelManaged(); rijndaelManaged.Key = keyArray; rijndaelManaged.Mode = CipherMode.ECB; rijndaelManaged.Padding = PaddingMode.PKCS7; ICryptoTransform icryptoTransform = rijndaelManaged.CreateEncryptor(); byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(toE); byte[] resultArray = icryptoTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length); return Convert.ToBase64String( resultArray, 0, resultArray.Length); } //解密字符串 public string Decryption(string toD) { //加密和解密必须采用相同的key,具体值自己填,但是必须为32位 byte[] keyArray = UTF8Encoding.UTF8.GetBytes("12345678123456781234567812345678"); RijndaelManaged rijndaelManaged = new RijndaelManaged(); rijndaelManaged.Key = keyArray; rijndaelManaged.Mode = CipherMode.ECB; rijndaelManaged.Padding = PaddingMode.PKCS7; ICryptoTransform cTransform = rijndaelManaged.CreateDecryptor(); byte[] toEncryptArray = Convert.FromBase64String(toD); byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length); return UTF8Encoding.UTF8.GetString(resultArray); }