Encryption and Compression Functions
955
The return string is a binary string where the first character is
CHAR(128 | key_num)
[886]
. If an
error occurs,
DES_ENCRYPT()
[954]
returns
NULL
.
The 128 is added to make it easier to recognize an encrypted key. If you use a string key,
key_num
is 127.
The string length for the result is given by this formula:
new_len
=
orig_len
+ (8 - (
orig_len
% 8)) + 1
Each line in the DES key file has the following format:
key_num
des_key_str
Each
key_num
value must be a number in the range from
0
to
9
. Lines in the file may be in any
order.
des_key_str
is the string that is used to encrypt the message. There should be at least one
space between the number and the key. The first key is the default key that is used if you do not
specify any key argument to
DES_ENCRYPT()
[954]
.
You can tell MySQL to read new key values from the key file with the
FLUSH DES_KEY_FILE
statement. This requires the
RELOAD
[577]
privilege.
One benefit of having a set of default keys is that it gives applications a way to check for the
existence of encrypted column values, without giving the end user the right to decrypt those values.
mysql>
SELECT customer_address FROM customer_table
>
WHERE crypted_credit_card = DES_ENCRYPT('credit_card_number');
•
ENCODE(str,pass_str)
[955]
Encrypt
str
using
pass_str
as the password. To decrypt the result, use
DECODE()
[954]
.
The result is a binary string of the same length as
str
.
The strength of the encryption is based on how good the random generator is. It should suffice for
short strings.
•
ENCRYPT(str[,salt])
[955]
Encrypts
str
using the Unix
crypt()
system call and returns a binary string. The
salt
argument
must be a string with at least two characters or the result will be
NULL
. If no
salt
argument is given,
a random value is used.
mysql>
SELECT ENCRYPT('hello');
-> 'VxuFAJXVARROc'
ENCRYPT()
[955]
ignores all but the first eight characters of
str
, at least on some systems. This
behavior is determined by the implementation of the underlying
crypt()
system call.
The use of
ENCRYPT()
[955]
with the
ucs2
multi-byte character set is not recommended because
the system call expects a string terminated by a zero byte.
If
crypt()
is not available on your system (as is the case with Windows),
ENCRYPT()
[955]
always returns
NULL
.
•
MD5(str)
[955]
Calculates an MD5 128-bit checksum for the string. The value is returned as a binary string of 32 hex
digits, or
NULL
if the argument was
NULL
. The return value can, for example, be used as a hash key.
See the notes at the beginning of this section about storing hash values efficiently.
mysql>
SELECT MD5('testing');
-> 'ae2b1fca515949e5d54fb22b8ed95575'
Содержание 5.0
Страница 1: ...MySQL 5 0 Reference Manual ...
Страница 18: ...xviii ...
Страница 60: ...40 ...
Страница 396: ...376 ...
Страница 578: ...558 ...
Страница 636: ...616 ...
Страница 844: ...824 ...
Страница 1234: ...1214 ...
Страница 1426: ...MySQL Proxy Scripting 1406 The following diagram shows an overview of the classes exposed by MySQL Proxy ...
Страница 1427: ...MySQL Proxy Scripting 1407 ...
Страница 1734: ...1714 ...
Страница 1752: ...1732 ...
Страница 1783: ...Configuring Connector ODBC 1763 ...
Страница 1793: ...Connector ODBC Examples 1773 ...
Страница 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Страница 1842: ...Connector Net Installation 1822 5 Once the installation has been completed click Finish to exit the installer ...
Страница 1864: ...Connector Net Visual Studio Integration 1844 Figure 20 24 Debug Stepping Figure 20 25 Function Stepping 1 of 2 ...
Страница 2850: ...2830 ...
Страница 2854: ...2834 ...
Страница 2928: ...2908 ...
Страница 3000: ...2980 ...
Страница 3122: ...3102 ...
Страница 3126: ...3106 ...
Страница 3174: ...3154 ...
Страница 3232: ...3212 ...