其实.NET Framework已经提供实现DES算法的类: System.Security.Cryptography.DESCryptoServiceProvider。之所以要把一个Delphi写的DES算法翻译成C#,是因为网友espnstar想用Delphi加密,C#解密,详见CSDN贴子: http://topic.csdn.net/t/20050726/18/4169690.html。
1
// Des.cs - 一个Delphi写的DES算法, 翻译成C#
2
// Wed 2005.09.14
3
4
// public byte[] EncryBytes (byte[] inData, byte[] keyByte);
5
// public byte[] DecryBytes (byte[] inData, byte[] keyByte);
6
// public string EncryStr (string Str, string Key );
7
// public string DecryStr (string Str, string Key );
8
// public string EncryStrHex(string Str, string Key );
9
// public string DecryStrHex(string StrHex, string Key );
10
11
namespace Skyiv
12
End of namespace Skyiv
感谢网友espnstar提供Delphi版的源程序:
2
3
4
5
6
7
8
9
10
11
12
1
unit Des;
2
3
.
2
3