如何在Dart中实现3des加密。
我下载了这个库(https://pub.dev/packages/tripledes),但是我无法添加所需的值。例如,如何传递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,mode,padding等
谢谢
发布于 2020-11-18 03:32:30
请勿使用3DES。这并不是因为加密了,所以它是安全的!
发布于 2020-11-18 03:28:55
在我的情况下,我的客户端使用ECB模式和DES.IV_ZEROS
我正在使用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);https://stackoverflow.com/questions/56857561
复制相似问题