Search Postgresql Archives

Re: Backslah in encrypt function.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jul 25, 2007 at 06:02:10PM +0530, Nalin Bakshi wrote:
>    I have come on a problem regarding encryption. I am firing a simple 
> select statement:
> 
> select encrypt('\\','abcd','bf');
> 
> I want to use \ for encryption but I get the error:
>            "invalid input syntax for type bytea"
> 
> I tried using \\\\ to encrypt \ , but on decryption I get \\ instead of 
> \ (single backslash).

The double backslash is the output representation of a single
backslash.  See Table 8-7 "bytea Literal Escaped Octets" and Table
8-8 "bytea Output Escaped Octets" in the documentation:

http://www.postgresql.org/docs/8.2/interactive/datatype-binary.html

You can use length(), octet_length(), or encode() to see that the
decrypted value contains only a single octet:

test=> select decrypt(encrypt(e'\\\\', 'abcd', 'bf'), 'abcd', 'bf');
 decrypt 
---------
 \\
(1 row)

test=> select octet_length(decrypt(encrypt(e'\\\\', 'abcd', 'bf'), 'abcd', 'bf'));
 octet_length 
--------------
            1
(1 row)

test=> select encode(decrypt(encrypt(e'\\\\', 'abcd', 'bf'), 'abcd', 'bf'), 'hex');
 encode 
--------
 5c
(1 row)

Depending on your security requirements you might wish to use
pgp_sym_encrypt() or pgp_sym_encrypt_bytea() instead of encrypt().
See the "Raw encryption" section of README.pgcrypto for some of the
disadvantages of encrypt().

-- 
Michael Fuhr


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux