Short Tag – Web Development Blog

Entries for the ‘Encryption’ Category

AES_ENCRYPT and AES_DECRYPT in php

Php doesn’t have direct functions for AES encryption and decryption like MySql.
These functions will do exactly what the MySql functions do.
Encypt function:

function AES_ENCRYPT($value, $secret)
{
return rtrim(
base64_encode(
mcrypt_encrypt(
[...]

Mysql AES_ENCRYPT not working properly

AES_ENCRYPT() is a MySql function for encrypting sensitive data, like passwords.
Usage examples:

SELECT AES_ENCRYPT("string","secret_key");
UPDATE `users` SET `encr_password` = AES_ENCRYPT("string", "secret_key");

The encrypted string will be binary, so it cannot be stored in a regular text field or varchar in MySql.
So, in this case:

UPDATE `users` SET `encr_password` = AES_ENCRYPT("string", "secret_key");

If `encr_password` field’s type is varchar or text then [...]