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