List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:September 20 2010 11:01pm
Subject:Re: SHA1 returns binary value
View as plain text  
On Sep 17, 2010, at 7:08 AM, Tompkins Neil wrote:

> Hi
> Why when I run the command (MySQL 5.1) SELECT SHA1('abc'); is it returned as
> a binary value and not a string value ?

If you mean, why is it a binary rather than a nonbinary (character) string,
that's true of most of the encryption or compression functions in 5.1. This was changed
in 5.5. says:

Many encryption and compression functions return strings for which the result might
contain arbitrary byte values. If you want to store these results, use a column with a
VARBINARY or BLOB binary string data type. This will avoid potential problems with
trailing space removal or character set conversion that would change data values, such as
may occur if you use a nonbinary string data type (CHAR,VARCHAR, TEXT).

Some encryption functions return strings of ASCII characters: MD5(), OLD_PASSWORD(),
PASSWORD(), SHA(),SHA1(). As of MySQL 5.5.3, their return value is a nonbinary string that
has a character set and collation determined by the character_set_connection and
collation_connection system variables. Before 5.5.3, these functions return binary
strings. The same change was made for SHA2() in MySQL 5.5.6.

Paul DuBois
Oracle Corporation / MySQL Documentation Team
Madison, Wisconsin, USA

SHA1 returns binary valueTompkins Neil17 Sep
  • Re: SHA1 returns binary valueAveek Misra17 Sep
  • Re: SHA1 returns binary valuePaul DuBois21 Sep
    • MySQL Error 1045Tim Thorburn21 Sep
      • Re: MySQL Error 1045Tim Thorburn21 Sep
        • Re: MySQL Error 1045Jigal van Hemert21 Sep