저는 AES 암호화 및 해독을위한 자바 알고리즘을 가지고 있으며 자바 스크립트에서 해독을 실현해야합니다.decryptAES from Java to node.js
public String encryptWithAES(String value, String key, String encoding) throws NoSuchAlgorithmException, NoSuchPaddingException, DecoderException, UnsupportedEncodingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
byte[] keyBytes = Hex.decodeHex(key.toLowerCase().toCharArray());
byte[] dataToSend = value.getBytes(encoding);
Cipher c = Cipher.getInstance("AES");
SecretKeySpec k = new SecretKeySpec(keyBytes, "AES");
c.init(1, k);
byte[] encryptedData = c.doFinal(dataToSend);
return new String(Hex.encodeHex(encryptedData));
}
public String decryptAES(String encrypted, String key, String encoding) throws NoSuchAlgorithmException, NoSuchPaddingException, DecoderException, UnsupportedEncodingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
byte[] keyBytes = Hex.decodeHex(key.toCharArray());
byte[] encryptedData = Hex.decodeHex(encrypted.toCharArray());
Cipher c = Cipher.getInstance("AES");
SecretKeySpec k = new SecretKeySpec(keyBytes, "AES");
c.init(2, k);
byte[] dencryptedData = c.doFinal(encryptedData);
return new String(dencryptedData, encoding);
}
인터넷에서 많은 예제를 발견했지만 아무도 적절한 결과를 얻지 못했습니다.
var algos = ['aes-128-cbc', 'aes-128-cfb', 'aes-128-cfb1', 'aes-128-cfb8', 'aes-128-ctr', 'aes-128-ecb', 'aes-128-gcm', 'aes-128-ofb', 'aes-128-xts', 'aes-256-cbc', 'aes-256-cfb', 'aes-256-cfb1', 'aes-256-cfb8', 'aes-256-ctr', 'aes-256-ecb', 'aes-256-gcm', 'aes-256-ofb', 'aes-256-xts', 'aes128', 'aes256'];
//var masterData - string like 'c07abe96dde490b3aba7d2f21a43ba94960619ff110ffb53433f0ff39f4cf138e48511b1fb4030'
//const ENCRYPTION_KEY - string like '94960619ff110ffb53433f0ff39f4cf1' with 32 symbols
function decrypt(text, algorithm) {
var decipher = crypto.createDecipher(algorithm, ENCRYPTION_KEY);
var dec = decipher.update(text, 'hex', 'utf8');
dec += decipher.final('utf8');
return dec;
}
algos.map(algo => {
try {
const dec = decrypt(masterData, algo);
console.log(algo, dec);
} catch (error) {
console.log(algo, 'error', error);
}
});
인코딩 된 문자열은 JSON입니다 :
는 지금은 그 코드를 해독하려고합니다.
Maven 알고리즘에 대해 이야기하고 있습니다. 그게 무슨 뜻입니까? Maven은 도구이며 알고리즘은 Java 기반입니까? – khmarbaise
예. 알고리즘은 maven 라이브러리에서 가져온 것입니다. http://grepcode.com/file/repo1.maven.org/maven2/com.google.code.maven-play-plugin.org.playframework/play/1.2.5/play/ libs/Crypto.java – MIchael