NodeS에서 3DS CBC 암호화 결과를 http://tripledes.online-domain-tools.com/에 복제해야합니다.TripleDes CBC Nodejs 구현 문제
const crypto = require('crypto');
const cipher = crypto.createCipher('des-ede3-cbc', key);
password = Buffer.from('MYPASS', 'utf8');
let encrypted = [cipher.update(password)];
encrypted.push(cipher.final());
encrypted = Buffer.concat(encryptedArr);
console.log(encrypted.toString('hex'));
tripledes.online-domain-tools.com의 결과이다 :
이
내 코드는 결과가 있어야하는 것으로 59 30 20 02 A5 8c dd 5e,하지만 내 코드 33 97 d8 b0 e3 00 d1 53.
내가 무엇이 누락 되었습니까?
Edit2가 :
const crypto = require('crypto');
function encrypt (inputkey, keyformat, password, passwordformat) {
let shortkey = Buffer.from(inputkey, keyformat);
let key = Buffer.alloc(24);
key.fill('\0');
for (i = 0; i < shortkey.length; i++) {
key[i] = shortkey[i];
}
let IV = Buffer.alloc(8);
const cipher = crypto.createCipheriv('des-ede3-cbc', key, IV);
password = Buffer.from(password, passwordformat);
let encryptedArr = [cipher.update(password)];
encryptedArr.push(cipher.final());
encrypted = Buffer.concat(encryptedArr);
return encrypted;
}
console.log(encrypt('1046913489980131','hex','0000000000000000','hex')); // works
console.log(encrypt('1007103489988020','hex','0000000000000000','hex')); // works
console.log(encrypt('10071034C8980120','hex','0000000000000000','hex')); // works
console.log(encrypt('1046103489988020','hex','0000000000000000','hex')); // works
console.log(encrypt('MYKEY','utf8','MYPASS','utf8')); // fails
NIST가 잘 작동의 모든 Permutation Operation Known Answer Test
하지만, 다른 몇 가지 : 당신의 제안에 따라 , 내 코드는 (또한 NIST 간행물의 안내로 만든 몇 가지 테스트를 추가) 변경 예제 (이미지 중 하나 포함)가 실패합니다.
내 서비스 공급자가 참조로 사용하고 있기 때문에이 그늘진 페이지로 테스트하는 이유가 있습니다.
초기화 벡터 유죄 수 있습니다에서 확인할 수있다. –
웹 페이지에는 필요한 키 길이와 일치하도록 키가 길어지고 키의 sha1을 IV로 사용한다고 나와 있습니다. 귀하의 코드는 그렇게하지 않습니다 – gusto2
나는 그것을 간과 할 것입니다. –