我只是问这个,因为我已经阅读了很多关于加密AES加密的帖子2天了,就在我以为我得到它的时候,我意识到我根本没有得到它.
这篇文章是我最接近我的问题,我有完全相同的问题,但没有答案:
我尝试过很多方面,但我没有做对.
首先
我正在获取已经加密的字符串(我只获得了代码以了解它们是如何进行的),因此修改加密方式不是一种选择.这就是为什么所有类似的问题对我都没有用.
第二
我有权访问密钥,我可以修改它(所以如果需要,调整长度是一个选项).
加密在CryptoJS上完成,它们将加密的字符串作为GET参数发送.
GetParamsForAppUrl.prototype.generateUrlParams = function() {
const self = this;
return new Promise((resolve, reject) => {
const currentDateInMilliseconds = new Date().getTime();
const secret = tokenSecret.secret;
var encrypted = CryptoJS.AES.encrypt(self.authorization, secret);
encrypted = encrypted.toString();
self.urlParams = {
token: encrypted,
time: currentDateInMilliseconds
};
resolve();
});
};
Run Code Online (Sandbox Code Playgroud)
我可以使用CryptoJS在javascript上轻松解密这个:
var decrypted = CryptoJS.AES.decrypt(encrypted_string, secret);
console.log(decrypted.toString(CryptoJS.enc.Utf8));
Run Code Online (Sandbox Code Playgroud)
但出于安全考虑,我不想在Javascript上这样做,所以我试图在Java上解密它:
String secret = "secret";
byte[] cipherText = encrypted_string.getBytes("UTF8");
SecretKey secKey = new SecretKeySpec(secret.getBytes(), "AES");
Cipher aesCipher = Cipher.getInstance("AES");
aesCipher.init(Cipher.DECRYPT_MODE, …Run Code Online (Sandbox Code Playgroud)