Answer a question

I'm working on field encrypt / decrypt.

What I choose is

select encrypt('123456789012345','1234','aes');
              encrypt               
------------------------------------
 \x34591627f9c8eae417fc7cbbf458592c
(1 row)

I got my data encrypted though, the other string is there after decrypt like below...

postgres=# select decrypt('\x34591627f9c8eae417fc7cbbf458592c','1234','aes');
             decrypt              
----------------------------------
 \x313233343536373839303132333435
(1 row)

Have I made wrong way? (I know this kind of asking could be stupid... )

What I have to do is just getting a most simple way and encrypted data has small size....

Thanks in advance...

Answers

The decrypt function is returning a byte string, not a character string, so its being shown in hex notation. The actual values are the same \x31 = 1, \x32 = 2 etc.

You need to cast the return value back to text.

eg:

select convert_from(decrypt('\x34591627f9c8eae417fc7cbbf458592c','1234','aes'),'SQL_ASCII');
  convert_from   
-----------------
 123456789012345
(1 row)

Postgresql string functions

Logo

PostgreSQL社区为您提供最前沿的新闻资讯和知识内容

更多推荐