用C#加密并在Flex中解密
作者:互联网
我需要在Flex中解密一些用C#加密并写入文件的数据.
为了简单起见,我使用as3crypto As3库和Bruce Schneier C#库选择河豚.
Bruce Schneier C# blowfish link
我可以得到一个短字符串在C#中加密并在Flex中解密
但是更长的字符串只会产生结果,我不知道我缺少什么?
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);
更新,一些样品
工作中
encrypt string = “watson?”
C# produces: 1514ea36fecfd5f5
AS3 produces: 1514ea36fecfd5f5
不工作
encrypt string = “whats up watson?”
C# produces: 3ea9808a4b9f74aaa8e54fe682947673
AS3 produces: 3ea9808a4b9f74aa20776174736f6e3f
非常相似但不匹配
如果我在C#中解密AS3密码,则会得到:
whats up?`r???
如果我在AS3中解密C#密码,则会得到:
whats up¨åO悔vs
解决方法:
AS3代码似乎不正确.工作示例代码:
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);
标签:encryption,blowfish,apache-flex,actionscript-3,c 来源: https://codeday.me/bug/20191201/2081465.html