Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在C#中加密,在Flex中解密_C#_Actionscript 3_Apache Flex_Encryption_Blowfish - Fatal编程技术网

在C#中加密,在Flex中解密

在C#中加密,在Flex中解密,c#,actionscript-3,apache-flex,encryption,blowfish,C#,Actionscript 3,Apache Flex,Encryption,Blowfish,我需要在Flex中解密一些用C#加密并写入文件的数据。 为了简单起见,我使用as3crypto As3库和Bruce Schneier C#库选择了河豚 我可以得到一个短字符串,用C#加密,用Flex解密 然而,更长的字符串无法产生结果,我不知道我缺少了什么 C#: AS3: 更新,部分样本 工作 加密字符串=“watson?” C#生产:1514ea36fecfd5f5 AS3生产:1514ea36fecfd5f5 不起作用 encrypt string=“沃森怎么了?” C#生产:3ea

我需要在Flex中解密一些用C#加密并写入文件的数据。 为了简单起见,我使用as3crypto As3库和Bruce Schneier C#库选择了河豚

我可以得到一个短字符串,用C#加密,用Flex解密 然而,更长的字符串无法产生结果,我不知道我缺少了什么

C#:

AS3:

更新,部分样本

工作

加密字符串=“watson?”

C#生产:1514ea36fecfd5f5

AS3生产:1514ea36fecfd5f5

不起作用

encrypt string=“沃森怎么了?”

C#生产:3ea9808a4b9f74aaa8e54fe682947673

AS3生产:3EA9808A4B9F74AA207766174736F6E3F

非常相似,但不匹配

如果我用C#解密AS3密码,我会得到:

怎么了?'r

如果我在AS3中解密C#密码,我会得到:

怎么了悔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);
回答“以后如何解密字符串”:


试试这个类,它可能会解决你的问题。

你能提供一个输出正确的例子,和一个输出不正确的例子吗?但我如何将cryptText bytearray转换成字符串,然后再解密该字符串?@kolaval-这个问题没有意义
cryptText
是包含加密数据的字节数组。
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);
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);
var encodedtxt:String = Hex.fromArray(cryptText);
cryptText = Hex.toArray(encodedtxt);
crypt.decrypt(cryptText);
package
{   
    import com.hurlant.crypto.Crypto;
    import com.hurlant.crypto.prng.Random;
    import com.hurlant.crypto.symmetric.ICipher;
    import com.hurlant.util.Base64;
    import com.hurlant.util.Hex;

    import flash.utils.ByteArray;

    import mx.utils.Base64Decoder;
    import mx.utils.Base64Encoder;

    public class EncryptionManager
    {

        public function EncryptionManager()
        {
        }

        public function enCrypt(data:String, keyStr:String):String
        {
            var key:ByteArray;
            var fileBytes:ByteArray = Hex.toArray(Hex.fromString(data));
            key = Hex.toArray(Hex.fromString(keyStr));

            var aes:ICipher = Crypto.getCipher("blowfish-ecb", key, Crypto.getPad("pkcs5"));
            aes.encrypt(fileBytes);

            var enc:Base64Encoder = new Base64Encoder();
            enc.encodeBytes(fileBytes);
            var result:String = enc.flush();
            return result;
        }

        public function deCrypt(data:String, keyStr:String):String
        {
            var key:ByteArray;

            var dec:Base64Decoder = new Base64Decoder();
            dec.decode(data);

            var fileBytes:ByteArray = dec.toByteArray();
            key = Hex.toArray(Hex.fromString(keyStr));
            var aes:ICipher = Crypto.getCipher("blowfish-ecb", key, Crypto.getPad("pkcs5"));
            aes.decrypt(fileBytes);
            return fileBytes.toString();
        }

    }
}