Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.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
Flutter 如何在颤振/飞镖中实现加密(3des)_Flutter_Dart - Fatal编程技术网

Flutter 如何在颤振/飞镖中实现加密(3des)

Flutter 如何在颤振/飞镖中实现加密(3des),flutter,dart,Flutter,Dart,如何在Dart中实现3des加密 我下载了这个库(),但是,我无法添加所需的值。。例如,如何传递iv值 下面是我需要转换为dart的JS代码(使用crypto.JS) { key = CryptoJS.enc.Utf8.parse(key); iv = CryptoJS.enc.Utf8.parse(ivKey); var options = { mode: CryptoJS.mode.CBC, padding: CryptoJS.p

如何在Dart中实现3des加密

我下载了这个库(),但是,我无法添加所需的值。。例如,如何传递iv值

下面是我需要转换为dart的JS代码(使用crypto.JS)

  {
     key = CryptoJS.enc.Utf8.parse(key);
     iv = CryptoJS.enc.Utf8.parse(ivKey);
     var options = {
       mode: CryptoJS.mode.CBC,
       padding: CryptoJS.pad.Pkcs7,
       iv: iv
     };
     var encrypted = CryptoJS.TripleDES.encrypt(token, key,  options);

    }
在Dart中,这就是我目前所拥有的

static String getEncrypt() {
    String key = HR_KEY;
    String id = "test";
    String message = id  + getUtcDate();
    var blockCipher = new BlockCipher(new TripleDESEngine(), key);
    var ciphertext = blockCipher.encodeB64(message);
    return ciphertext;
  }
使用上述代码,如何传递iv、模式、填充等


谢谢

在我的情况下,我的客户使用的是
ECB
模式和
DES.IV_零

我使用的是
dart_des
软件包,我通过以下代码实现了接近您问题的解决方案:

  String key = apiObject.key;
  Uint8List data = convert.base64Decode(key);

  DES3 desECB = DES3(key: data, mode: DESMode.ECB, iv: DES.IV_ZEROS);

  String cypher = "cypher text";
  List<int> bytes = convert.utf8.encode(cypher);
  bytes = [bytes[0], 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]; // this is the secret
  // create a 8 positions byte array, and the first one is the only one that you update
  //and after this you encrypt the byte key with TripleDes
  List<int> encryptedChyper = desECB.encrypt(bytes);

  String value = convert.base64Encode(encryptedChyper);
String key=apobject.key;
UINT8列表数据=convert.base64解码(键);
DES3 desECB=DES3(键:数据,模式:DESMode.ECB,iv:DES.iv_零);
字符串cypher=“cypher text”;
列表字节=convert.utf8.encode(cypher);
字节=[字节[0],0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];//这就是秘密
//创建一个8位字节数组,第一个是唯一要更新的
//然后用三元组加密字节密钥
List encryptedChyper=desECB.encrypt(字节);
字符串值=convert.base64Encode(encryptedChyper);

不要使用3DES。这不是因为它是加密的,它是安全的

你找到解决办法了吗?没有。。我在节点/后端实现它,然后从我的应用程序调用它。欢迎使用StackOverflow。在编写答案时,您可能需要解释为什么您认为您的答案是正确的,因为它可能不是针对完全相同的问题,并且解释可能有助于了解为什么3DES仅以通常的方式加密8字节数组。第一个位置是要加密的值,其余7个位置是随机值。下面的答案进一步解释了该技术的工作原理。这不安全,只是味道不好。