在 C# 中加密并在 Flex 中解密 [英] Encrypt in C# and decrypt in Flex
问题描述
我需要在 Flex 中解密一些在 C# 中加密并写入文件的数据.为简单起见,我使用 as3crypto As3 库和 Bruce Schneier C# 库选择了河豚.
I need to decrypt some data in Flex that is encrypted in C# and written to a file. I settled on blowfish for simplicity's sake using the as3crypto As3 library and Bruce Schneier C# library.
我可以得到一个短字符串在 C# 中加密并在 Flex 中解密但是更长的字符串无法产生结果,我不知道我错过了什么?
I can get a short string to encrypt in C# and decrypt in Flex fine however longer strings just fail to produce results and I do not know what I am missing?
C#:
string reportstring = "watson?";
BlowFish b = new BlowFish("04B915BA43FEB5B6");
string cipherText = b.Encrypt_ECB(reportstring);
String plainText = b.Decrypt_ECB(cipherText);
AS3:
var txt:String = "watson?";
var key:ByteArray = Hex.toArray("04B915BA43FEB5B6");
var blowfish:BlowFishKey = new BlowFishKey(key);
var dataBytes:ByteArray = new ByteArray();
dataBytes=Hex.toArray(Hex.fromString(txt));
blowfish.encrypt(dataBytes);
blowfish.decrypt(dataBytes);
更新,一些示例
工作
加密字符串 = "watson?"
C# 产生:1514ea36fecfd5f5
C# produces: 1514ea36fecfd5f5
AS3 产生:1514ea36fecfd5f5
AS3 produces: 1514ea36fecfd5f5
不工作
加密字符串 = "whats up watson?"
C# 产生:3ea9808a4b9f74aaa8e54fe682947673
C# produces: 3ea9808a4b9f74aaa8e54fe682947673
AS3 产生:3ea9808a4b9f74aa20776174736f6e3f
AS3 produces: 3ea9808a4b9f74aa20776174736f6e3f
非常相似但不匹配
如果我在 C# 中解密 AS3 密码,我会得到:
if I decrypt the AS3 cipher in C# I get :
怎么了?`r???
如果我在 AS3 中解密 C# 密码,我会得到:
if I decrypt the C# cipher in AS3 I get :
whats up¨åO悔vs
whats up¨åO悔vs
推荐答案
AS3 代码似乎不正确.工作示例代码:
The AS3 code seems to be incorrect. Working example code:
import com.hurlant.util.Hex;
import com.hurlant.util.Base64;
import com.hurlant.crypto.Crypto;
import flash.utils.ByteArray;
import com.hurlant.crypto.symmetric.IPad;
import com.hurlant.crypto.symmetric.ICipher;
import com.hurlant.crypto.symmetric.NullPad;
import com.hurlant.crypto.symmetric.BlowFishKey;
function encrypt($text:String, $cryptKey:ByteArray):String
{
var iPad:IPad = new NullPad();
var crypt = Crypto.getCipher('blowfish-ecb',$cryptKey,iPad);
var cryptText:ByteArray = new ByteArray();
cryptText.writeUTFBytes( $text );
crypt.encrypt( cryptText );
trace( Hex.fromArray( cryptText ) );
return null;
}
var txt:String = "whats up watson?";
var key:ByteArray = Hex.toArray("04B915BA43FEB5B6");
encrypt(txt, key);
这篇关于在 C# 中加密并在 Flex 中解密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!