【发布时间】:2013-10-30 09:30:05
【问题描述】:
我正在尝试加密/解密要在查询字符串中使用的数据。
大多数时候,加密数据以“等号”符号'='结尾
以下是一些加密字符串的例子
1 - LS07D43u6Hs=
2 - oHPgq6hz0A0=
3 - 4ugeuARQvXw=
abc - gZfrQVAk9Ic=
encode me - RfSQYXX1P4MU7LhMsfsG8w==
我从这里复制了代码并进行了一些更改。
http://www.deltasblog.co.uk/code-snippets/basic-encryptiondecryption-c/
byte[] inputArray = UTF8Encoding.UTF8.GetBytes("encode me");
TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider();
tripleDES.Key = UTF8Encoding.UTF8.GetBytes("abcd123456Idlaaz");
tripleDES.Mode = CipherMode.ECB;
tripleDES.Padding = PaddingMode.PKCS7;
ICryptoTransform cTransform = tripleDES.CreateEncryptor();
byte[] resultArray = cTransform.TransformFinalBlock(inputArray, 0, inputArray.Length);
tripleDES.Clear();
Response.Write(Convert.ToBase64String(resultArray, 0, resultArray.Length));
我尝试更改 Key、PaddingMode、CipherMode,但没有成功。它总是在最后返回 = 。请帮帮我。
【问题讨论】:
-
这是 Base64 填充,所以它是由
ToBase64String添加的,而不是由 3DES 添加的。
标签: c#-4.0 encryption tripledes