How can I translate this JavaScript code into Java using javax.crypto.xxx?
encryptString : function encryptString(str, password) {
var cipher = crypto.createCipher("aes128", password);
return cipher.update(str, "binary", "base64") +
cipher.final("base64");
},
decryptString : function decryptString(str, password) {
var desipher = crypto.createDecipher("aes128", password);
return desipher.update(str, "base64", "binary") +
desipher.final("binary");
}
I plan to encode in JS and decode in Java, as well as vice versa. Both 'str' and 'password' variables are strings, with the 'password' being 16 characters long.
It seems that the createCipher(algorithm, password) method utilizes a unique approach to generate raw key and IV, which may not be standard across different platforms. Switching to createCipheriv(algorithm, key, iv) could provide a more versatile solution. For more information, check out: http://nodejs.org/api/crypto.html#crypto_crypto_createcipheriv_algorithm_key_iv I will make sure to update with the latest information soon.