Reputation: 5059
With the string "123456Adrian Wapcaplet"
I need to
I need help with #1 and #3. Below is how I generate this in Linux
$ echo -n "123456Adrian Wapcaplet" | shasum -a 256 | cut -c33-64 | xxd -r -p | base64
jNWe9TyaqmgxG3N2fgl15w==
Upvotes: 2
Views: 4359
Reputation: 7286
Install the pgcrypto extension:
create extension pgcrypto;
Then you can use the digest
function to do sha256. The rest of the functions you'll need are built in:
select encode(substring(digest('123456Adrian Wapcaplet', 'sha256') from 17), 'base64');
Note that there's an implicit cast from text
to bytea
performed here when calling digest
. It will use the default encoding for the database. To avoid problems due to environmental differences you can specify the encoding for the conversion:
digest(convert_to('123456Adrian Wapcaplet', 'utf8'), 'sha256')
Upvotes: 2