"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Why Does AES_DECRYPT() Return an Empty Result in MySQL?

Why Does AES_DECRYPT() Return an Empty Result in MySQL?

Published on 2024-11-13
Browse:556

Why Does AES_DECRYPT() Return an Empty Result in MySQL?

Troubleshooting AES_DECRYPT Failure in MySQL

When attempting to decrypt data previously encrypted with AES_ENCRYPT(), you may encounter an issue where AES_DECRYPT() returns an empty result. This can be frustrating, as your encrypted data remains inaccessible.

According to the MySQL documentation, AES_DECRYPT() is expected to return the original string após decrypting an encrypted string. However, in some cases, it may return a binary string instead.

To resolve this issue, try the following:

SELECT *,
       CAST(AES_DECRYPT(first_name, 'usa2010') AS CHAR(50)) first_name_decrypt
FROM   user

This query uses the CAST() function to convert the decrypted binary string to a CHAR string, which can be displayed properly. Instead of using "first_name" in your subsequent queries or applications, use "first_name_decrypt" to access the decrypted data.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3