AES_DECRYPT issues

Hi,

I am having trouble using AES_DECRYPT in php my admin,

THE AES_ENCRYPT function seems to work fine, however Whenever I decrypt a number using AES_DECRYPT, it comes back with a 3 in between each digit. I.e., if the number I encrypted was 11111, when I use AES_DECRYPT it returns 3131313131. I have tried a whole bunch of numbers of different lengths and the all come back with 3’s in front of each digit.

The actual code I have used is as follows:

INSERT INTO test (id, card_number) VALUES (NULL, AES_ENCRYPT(1234567890, ‘salt’));

then…

SELECT id, AES_DECRYPT(card_number, ‘salt’) FROM test;

the result is 31323334353637383930

id is setup as INT UNSIGNED NOT NULL AUTO_INCREMENT
card_number is TINYBLOB

Can anyone help me please?!

The MySQL AES_ENCRYPT function encrypts strings not numerics. Maybe try putting the card number inside quotation marks?

This was the function that my textbook suggested I used, Is there another one that would work better??, I tried putting the card number in quotation marks and got the same result…

If you are planning to encrypt credit card numbers, you might want to read over the PCI Complicance for handling credit cards first.

Storing the credit card number (even when encrypted) without following being PCI Complient for the level required can lead to a fine in hundred thousands dollar range.

Instead look into a merchant that provide a card profile option, since the PCI Compliance required to store credit card numbers cost quite a lot just in hardware costs per month.