加密在C#和解密的Flex [英] Encrypt in C# and decrypt in Flex
问题描述
我需要Flex中一些数据被加密C#和写入文件进行解密。 我用as3crypto AS3库和布鲁斯的C#库结算河豚为简单起见。
我可以得到一个短字符串在C#中进行加密和解密的Flex精 但是长字符串只是未能产生结果,我不知道我缺少的是什么?
C#:
字符串reportstring =?沃森;
河豚B =新河豚(04B915BA43FEB5B6);
串密文= b.Encrypt_ECB(reportstring);
字符串明文= b.Decrypt_ECB(密文);
AS3:
VAR TXT:字符串=?沃森;
VAR键:的ByteArray = Hex.toArray(04B915BA43FEB5B6);
VAR河豚:BlowFishKey =新BlowFishKey(密钥);
VAR dataBytes:ByteArray的=新的ByteArray();
dataBytes = Hex.toArray(Hex.fromString(TXT));
blowfish.encrypt(dataBytes);
blowfish.decrypt(dataBytes);
更新,一些样品
工作
加密字符串=沃森?
C#生产:1514ea36fecfd5f5
AS3 生产:1514ea36fecfd5f5
不工作
加密字符串=怎么了华生?
C#生产:3ea9808a4b9f74aaa8e54fe682947673
AS3 生产:3ea9808a4b9f74aa20776174736f6e3f
,这是非常相似但不匹配
如果我解密C#的AS3密码我得到:
怎么了?`R 111
如果我解密C#密码在AS3中,我得到:
什么up¨åO悔VS
在AS3 code似乎是不正确的。工作例如code:
进口com.hurlant.util.Hex;
进口com.hurlant.util.Base64;
进口com.hurlant.crypto.Crypto;
进口flash.utils.ByteArray的;
进口com.hurlant.crypto.symmetric.IPad;
进口com.hurlant.crypto.symmetric.ICipher;
进口com.hurlant.crypto.symmetric.NullPad;
进口com.hurlant.crypto.symmetric.BlowFishKey;
函数加密($文字:字符串,$ cryptKey:ByteArray)中:字符串
{
VAR的iPad:iPad的=新NullPad();
VAR隐窝= Crypto.getCipher('河豚,欧洲央行,$ cryptKey,iPad的);
VAR cryptText:ByteArray的=新的ByteArray();
cryptText.writeUTFBytes($文本);
crypt.encrypt(cryptText);
跟踪(Hex.fromArray(cryptText));
返回null;
}
VAR TXT:字符串=怎么了华生?
VAR键:的ByteArray = Hex.toArray(04B915BA43FEB5B6);
加密(TXT,密钥);
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.
Bruce Schneier C# blowfish link
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);
Update, some samples
working
encrypt string = "watson?"
C# produces: 1514ea36fecfd5f5
AS3 produces: 1514ea36fecfd5f5
not working
encrypt string = "whats up watson?"
C# produces: 3ea9808a4b9f74aaa8e54fe682947673
AS3 produces: 3ea9808a4b9f74aa20776174736f6e3f
which is very similar but not matching
if I decrypt the AS3 cipher in C# I get :
whats up?`r???
if I decrypt the C# cipher in AS3 I get :
whats up¨åO悔vs
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屋!