Prashant 쿠마 샤르마 :
나는 복제하는 것을 시도하고 자바 에 대한 코드 AES 암호화 및 암호 해독 에 노드 JS를 .
자바 코드
SecretKeySpec skeySpec;
String key = "a4e1112f45e84f785358bb86ba750f48";
public void encryptString(String key) throws Exception {
try {
skeySpec = new SecretKeySpec(key.getBytes(), "AES");
cipher = Cipher.getInstance("AES");
cipher.init(1, skeySpec);
byte encstr[] = cipher.doFinal(message.getBytes());
String encData = new String(encstr, "UTF-8");
System.out.println(encData);
} catch (NoSuchAlgorithmException nsae) {
throw new Exception("Invalid Java Version");
} catch (NoSuchPaddingException nse) {
throw new Exception("Invalid Key");
}
}
노드 JS
var encryptKey = function (text) {
var cipher = crypto.createCipher('aes256', 'a4e1112f45e84f785358bb86ba750f48');
var crypted = cipher.update(text,'utf8', 'hex')
crypted += cipher.final('hex');
console.log(crypted);
return crypted;
}
나는 정확한 얻을 수 없습니다입니다 암호문 의 노드 JS 내가 점점하고, 자바 .
Prashant 쿠마 샤르마 :
마지막으로 검토 한 후 자바 문서 와 노드 JS 암호화 문서는 결과를 얻을 수 있었다. 우리는 사용해야하는 crypto.createCipheriv()
대신 crypto.createCipher
IV와 함께. 여기에 IV가 될 것입니다 null
.
코드 :
let crypto = require('crypto');
var iv = new Buffer.from(''); //(null) iv
var algorithm = 'aes-256-ecb';
var password = 'a4e1112f45e84f785358bb86ba750f48'; //key password for cryptography
function encrypt(buffer){
var cipher = crypto.createCipheriv(algorithm,new Buffer(password),iv)
var crypted = Buffer.concat([cipher.update(buffer),cipher.final()]);
return crypted;
}
console.log(encrypt(new Buffer('TextToEncrypt')).toString())