c#中是否已有任何内容,并提供了一个在Java中执行类似操作的示例。我正在尝试下面的代码。加密看起来正确吗?它有一堆?标记。
Cipher cipher = Cipher.getInstance("BlowFish/ECB/PKCS5Padding");
byte[] keyBytes = Encoding.ASCII.GetBytes(key);
string keyHex = Hex.ToHexString(keyBytes); //4b334c33315551354f38325059344739
string parameters = "{\"userId\":\"6440870\"}";
byte[] parametersByte = Encoding.ASCII.GetBytes(parameters);
string parametersHex = Hex.ToHexString(parametersByte); //7b22757365724964223a2236343430383730227d
BlowFish bl = new BlowFish(keyHex);
byte[] outputEncryptedByte = bl.Encrypt_ECB(parametersByte);
string outputEncrypted = Encoding.ASCII.GetString(outputEncryptedByte); //7lC[t$?mQd?g???kE?W?[?
string outputBase64 = System.Convert.
ToBase64String(outputEncryptedByte); // N2xDW3Qk / xgObVFkpmfBgchrRepXnVu9
最佳答案
它没有在Framework中实现,但是您可以从此处获得C#的实现。
http://www.schneier.com/blowfish-download.html
只需将代码放在项目目录中的.cs文件中,然后像这样使用它即可。
BlowFish b = new BlowFish("04B915BA43FEB5B6");
string plainText = "The quick brown fox jumped over the lazy dog.";
string cipherText = b.Encrypt_CBC(plainText);
MessageBox.Show(cipherText);
plainText = b.Decrypt_CBC(cipherText);
MessageBox.Show(plainText);
关于c# - Java中C#中的河豚,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6119359/