« MySQL Pop Quiz #26 | Main | MySQL Function of the Day: Week Seven »
ENCODE() :: MySQL Function of the Day
By Carsten | April 28, 2008
Function name: ENCODE
Aliases: -
Function type: Encryption function
Purpose: Encrypt a string using a password
Description: ENCODE(’bitbybit.dk’, ‘bIgS3cR3t’) returns “bIQu/AJkKCHU2″, which is the encryption of the string ‘bitbybit’ using the password ‘bIgS3cR3t’.
To decrypt the string, use DECODE:
mysql> select DECODE('bIQu/AJkKCHU2', 'bIgS3cR3t');
+---------------------------------------------------+
| DECODE('bIQu/AJkKCHU2', 'bIgS3cR3t') |
+---------------------------------------------------+
| bitbybit.dk |
+---------------------------------------------------+ 1 row in set (0.00 sec)
If you copy-pasted any of the above, it probably didn’t work: ENCODE returns a binary string, which may well contain extended characters.
ENCODE/DECODE doesn’t provide you with national-security encryption, but it ought to suffice for encrypting short messages or other small pieces of information.
MySQL manual entry on ENCODE()
MySQL Function of the Day is a small series of concise information regarding most of the functions and operators available in MySQL. Inspired by PHPs funcaday, it’s meant to provide a daily dose of something in-between “Aha!” and “Ho-hum, I knew that already”, depending on your level of experience with MySQL. You can access the entire series with your browser here or pick up the RSS feed here.
Topics: MySQL Function of the day |