首页 新闻 赞助 找找看

求高手看看des的加密问题

0
悬赏园豆:10 [已关闭问题]
<P>标准的des 在c#中是不是只能使用8字节(64位)的密钥加密啊??<BR>别人使用java加密的数据,他们的密钥一共有49字节(49个字母),但是.net中只能接收8个字节的密钥啊?<BR>请高手说明des在c++中 c#中 java中 有什么区别&nbsp; C#怎么能够接收49字节的密钥??</P> <P>谢谢</P>
炮雷的主页 炮雷 | 初学一级 | 园豆:190
提问于:2008-08-21 10:26
< >
分享
其他回答(2)
0
期待高手的回答
燕山又飘雪 | 园豆:195 (初学一级) | 2008-08-21 11:19
0
DES标准就是64位输入+64位密钥(有效56位吧)产生64位输出,因此8字节的密钥才是正确的,至于JAVA中的49字节,可能是内部又作了一些变换最后选择了8个字节的密钥
Gray Zhang | 园豆:17610 (专家六级) | 2008-08-21 15:53
0
DES 标准确实只支持 64 位密钥。 如果你需要更高位的DES,可以使用3DES加密算法,这个算法可以支持128位和192位的密钥。 下面是例子 /// <summary> /// Encrypt by 3DES /// </summary> /// <param name="input">input stream</param> /// <param name="output">output stream</param> /// <param name="key">Key, the size must be 16 or 24 and it must be a strong key!</param> /// <param name="iv">IV, the size must be 8</param> /// <param name="bufSize">the size of buffer</param> public static void EncryptBy3DES(Stream input, Stream output, byte[] key, byte[] iv, int bufSize) { CryptoStream cStream = new CryptoStream(output, new TripleDESCryptoServiceProvider().CreateEncryptor(key, iv), CryptoStreamMode.Write); // Create a StreamWriter using the CryptoStream. BinaryWriter sWriter = new BinaryWriter(cStream); int readBytes = 0; byte[] buf = new byte[bufSize]; // Read from input, write to crypto stream while (true) { readBytes = input.Read(buf, 0, buf.Length); if (readBytes == 0) { break; } sWriter.Write(buf, 0, readBytes); } cStream.FlushFinalBlock(); } /// <summary> /// Encrypt by 3DES /// </summary> /// <param name="stream">input string</param> /// <param name="key">Key, the size must be 16 or 24 and it must be a strong key!</param> /// <param name="iv">IV, the size must be 8</param> /// <returns>Encrypted string</returns> public static string En
eaglet | 园豆:17139 (专家六级) | 2008-08-22 13:48
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册