简体   繁体   English

解密用 CryptoJS 加密的 mysql 中的 AES

[英]Decrypt AES in mysql that was encrypted with CryptoJS

In my database i have a column that stores cryptojs encrypted values in this type of form:在我的数据库中,我有一列以这种形式存储 cryptojs 加密值:

U2FsdGVkX1/BpEUjr5y+hivlNpUep+HZQG4Tw8bmTvQ= U2FsdGVkX1/BpEUjr5y+hivlNpUep+HZQG4Tw8bmTvQ=

When i decrypt this with cryptojs it's all good.当我用cryptojs解密它时,一切都很好。

let decryptedValue = cryptoJS.AES.decrypt(
    encryptedField,
    secretKey
 );

But decrypting it with mysql returns null.但是用 mysql 解密它会返回 null。

I've tried converting to the encrypted string into binary then decrypting it with mysql's aes_decrypt() but it returns null.我尝试将加密的字符串转换为二进制,然后用mysql的aes_decrypt()解密它,但它返回null。

SELECT convert(AES_DECRYPT(binary(encrypted_field),'secret_key') using utf8) as decrypt

The encrypted values are numbers and i need to decrypt them in order to do some calculations in mysql with them.加密的值是数字,我需要解密它们以便在 mysql 中使用它们进行一些计算。

I don't know if there is something wrong with the way i'm decrypting it or do cryptojs and mysql have different ways of encrypting and decrypting using AES.我不知道我解密它或做cryptojs的方式是否有问题,mysql有不同的使用AES加密和解密的方式。

Thank you in advance.先感谢您。

It looks like your initial string is Base64 Encoded .看起来您的初始字符串是Base64 Encoded It's possible that cryptoJS.AES or some other process is taking the encrypted bytes and storing them as Base64 in the database. cryptoJS.AES或其他一些进程可能正在获取加密字节并将它们作为Base64存储在数据库中。

Your databases decrypt routine is probably assuming the raw bytes, so you'll need to turn the Base64 string (check the net for mysql's base64 routines) into the actual bytes and then pass them to the AES_DECRYPT function.您的数据库解密例程可能假定原始字节,因此您需要将Base64字符串(检查 mysql 的 base64 例程的网络)转换为实际字节,然后将它们传递给AES_DECRYPT ZC1C425Z574117AB984D41

Not sure if your question still remains but here is a suggestion to use an alternate to CryptoJS.不确定您的问题是否仍然存在,但这里建议使用 CryptoJS 的替代品。 I found a Node JS implementation of MySQL AES encryption & decryption.我找到了 MySQL AES 加密和解密的 Node JS 实现。 This library helped me to encrypt data that is readable in MySQL too.这个库帮助我加密在 MySQL 中可读的数据。

Here is the link:链接在这里:

https://www.npmjs.com/package/mysql-aes https://www.npmjs.com/package/mysql-aes

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM