|
|
In the following query we use AES_ENCRYPT()
function to encrypt Department name. AES_ENCRYPT() function uses the
official AES (Advanced Encryption Standard) algorithm employing a 128-bit key:
SELECT DeptName, AES_ENCRYPT(DeptName, 'bampi')
FROM Departments
/* you can chose complicated key like this */
SELECT DeptName, AES_ENCRYPT(DeptName, 'Kx73oR4g9Bz')
FROM Departments
/* key can be number */
SELECT DeptName, AES_ENCRYPT(DeptName, '987')
FROM Departments
|
The results will be as following:
| DeptName | AES_ENCRYPT(DeptName, '987') |
| management | ?rJh8ê??.ÑâiÃg)I |
| logistic | .‰p“Ö?ñù)åÖêõ?? |
| advertizing | º¤çoÅc§Ò5H?×C:ï× |
| accounting | @iT™.Àë..áw?.Õ™3 |
| sales | ÷ðô:'?.¼Ì.ä ?ãIæ |
The way back from encrypted state is easy with AES_DECRYPT()
that returns to Department name it's human meaning:
SELECT DeptName,
AES_ENCRYPT(DeptName, '987') AS NameEncrypted,
AES_DECRYPT(AES_ENCRYPT(DeptName, '987'),'987') AS NameDecrypted
FROM Departments
|
The results will be as following:
| DeptName | NameEncrypted | NameDecrypted |
| management | ?rJh8ê??.ÑâiÃg)I | management |
| logistic | .‰p“Ö?ñù)åÖêõ?? | logistic |
| advertizing | º¤çoÅc§Ò5H?×C:ï× | advertizing |
| accounting | @iT™.Àë..áw?.Õ™3 | accounting |
| sales | ÷ðô:'?.¼Ì.ä ?ãIæ | sales |
MySQL Help says that AES_ENCRYPT() and AES_DECRYPT() can be
considered the most cryptographically secure encryption functions available
for the current version (5.1) of this DBMS.
|