有人知道3des算法吗? DES(KL,DES-1(KR,DES(KL,X))), 究竟怎样用work key "31313131313131313232323232323232" 来加密"33333333333333333333333333333333"呢?(用3des算法)望高手指教! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://www.codeproject.com/samples/cryptest__mfc_style_.asp http://www.fpga.com.cn/application/a69.htm 本代码参照了部分MSDN上的代码示例,再根据自己的实际情况,补充了一部分MSDN上没有提到的内容 using System;using System.Security;using System.Security.Cryptography;using System.IO;using System.Text;using System.Threading; namespace TRIP3DES{ /// /// Class1 的摘要说明。 /// public class dllEncrypt { //密钥 private const string sKey = "qJzGEh6hESZDVJeCnFPGuxzaiB7NLQM3"; //矢量,矢量可以为空 private const string sIV = "qcDY6X+aPLw="; //构造一个对称算法 private SymmetricAlgorithm mCSP = new TripleDESCryptoServiceProvider(); public dllEncrypt(){} #region public string EncryptString(string Value) /// /// 加密字符串 /// /// 输入的字符串 /// 加密后的字符串 public string EncryptString(string Value) { ICryptoTransform ct; MemoryStream ms; CryptoStream cs; byte[] byt; mCSP.Key = Convert.FromBase64String(sKey); mCSP.IV = Convert.FromBase64String(sIV); //指定加密的运算模式 mCSP.Mode = System.Security.Cryptography.CipherMode.ECB; //获取或设置加密算法的填充模式 mCSP.Padding = System.Security.Cryptography.PaddingMode.PKCS7; ct = mCSP.CreateEncryptor(mCSP.Key, mCSP.IV); byt = Encoding.UTF8.GetBytes(Value); ms = new MemoryStream(); cs = new CryptoStream(ms, ct, CryptoStreamMode.Write); cs.Write(byt, 0, byt.Length); cs.FlushFinalBlock(); cs.Close(); return Convert.ToBase64String(ms.ToArray()); } #endregion #region public string DecryptString(string Value) /// /// 解密字符串 /// /// 加过密的字符串 /// 解密后的字符串 public string DecryptString(string Value) { ICryptoTransform ct; MemoryStream ms; CryptoStream cs; byte[] byt; mCSP.Key = Convert.FromBase64String(sKey); mCSP.IV = Convert.FromBase64String(sIV); mCSP.Mode = System.Security.Cryptography.CipherMode.ECB; mCSP.Padding = System.Security.Cryptography.PaddingMode.PKCS7; ct = mCSP.CreateDecryptor(mCSP.Key, mCSP.IV); byt = Convert.FromBase64String(Value); ms = new MemoryStream(); cs = new CryptoStream(ms, ct, CryptoStreamMode.Write); cs.Write(byt, 0, byt.Length); cs.FlushFinalBlock(); cs.Close(); return Encoding.UTF8.GetString(ms.ToArray()); } #endregion }} 三、总结做成类库对于密钥和矢量的保管比较方便,输入输出全部是string型变量,这样也比较方便,密钥的生成可以用mSCP. GenerateKey()来生成,矢量的生成也可以用mCSP.GenerateIV()来生成。大家也可以自己灵活的编写符合自己的3DES算法。 我现在有基于C代码的Des算法,3Des算法只是Des算法的衍生,这个公式DES(KL,DES-1(KR,DES(KL,X)))是我在网上看到的,现在有一个问题,因为单Des算法接收的key和data(待加密数据)均是16byte,根据上述公式,我认为3des算法就是进行3次des运算,也就是将32位的key划分成left key(16byte)和right key(16byte),即上述公式中的KL和KR,但是这样理解有一个矛盾是X(待加密数据)的长度问题,因为单des算法中X的长度应该是16byte,但实际上3des算法加密的数据长度是32byte(与key 长度对应),所以困惑中...... 请高手指教! 知道了,就是x实际上只能是16byte,如果是32byte,将它分为2次分别计算。 如何在指定Dialog中进行PPT幻灯片放映? MessageBox,它是怎样根据文字量来自动调整大小的?点击其它地方时,它的标题栏总是一闪一闪的,所以我想自己做一个来模拟,把闪去掉。 嘉兴地区的进来报个名:) 界面编程问题,在线等 HJSkinPro 是什么软件 怎么指定动态库所在的路径呢? Word在没有安装打印机的情况下可以进行打印预览,而用VC向导生成的程序却不行,为什么,有解决的办法吗? 关于互斥按钮(radio button)的问题请教高手 高手救急,在线等~!! 学习MFC该从哪里入手,我有C的基础,学VC从哪里入手?抱歉没分了 求教:要获得一张图里几个点的坐标可以用什么软件? 如何实现自动化对象象word一样,
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货