我正在尝试使用ECB模式的TripleDES加密.我的代码看起来像这样:
public static string EncryptDES(string InputText)
{
byte[] key = new byte[] { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48 };
byte[] clearData = System.Text.Encoding.UTF8.GetBytes(InputText);
MemoryStream ms = new MemoryStream();
TripleDES alg = TripleDES.Create();
alg.Key = key;
alg.Mode = CipherMode.ECB;
CryptoStream cs = new CryptoStream(ms, alg.CreateDecryptor(), CryptoStreamMode.Write);
cs.Write(clearData, 0, clearData.Length);
cs.FlushFinalBlock();
byte[] CipherBytes = ms.ToArray();
ms.Close();
cs.Close();
string EncryptedData = Convert.ToBase64String(CipherBytes);
return EncryptedData;
}
Run Code Online (Sandbox Code Playgroud)
当我运行测试时,我得到一个例外,即"要解密的数据长度无效".
有谁知道我做错了什么?
先感谢您.
我的错 !我发现了我的问题而不是使用alg.CreateEncryptor()我正在使用alg.CreateDecyptor().
复制粘贴问题.:(
谢谢你的帮助,伙计们
| 归档时间: |
|
| 查看次数: |
8228 次 |
| 最近记录: |