DES 标准确实只支持 64 位密钥。
如果你需要更高位的DES,可以使用3DES加密算法,这个算法可以支持128位和192位的密钥。
下面是例子
///
/// Encrypt by 3DES
///
/// input stream
/// output stream
/// Key, the size must be 16 or 24 and it must be a strong key!
/// IV, the size must be 8
/// the size of buffer
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();
}
///
/// Encrypt by 3DES
///
/// input string
/// Key, the size must be 16 or 24 and it must be a strong key!
/// IV, the size must be 8
/// Encrypted string
public static string En
eaglet
|
园豆:17119
(专家六级)
|
2008-08-22 13:48
Ctrl+Enter键快速提交