mirror of
https://github.com/postgres/postgres.git
synced 2025-07-18 17:42:25 +03:00
pgcrypto: Remove explicit hex encoding/decoding from tests
This was from before the hex format was available in bytea. Now we can remove the extra explicit encoding/decoding calls and rely on the default output format. Discussion: https://www.postgresql.org/message-id/flat/17dcb4f7-7ac1-e2b6-d5f7-2dfba06cd9ee%40enterprisedb.com
This commit is contained in:
@ -1,70 +1,64 @@
|
|||||||
--
|
--
|
||||||
-- 3DES cipher
|
-- 3DES cipher
|
||||||
--
|
--
|
||||||
-- ensure consistent test output regardless of the default bytea format
|
|
||||||
SET bytea_output TO escape;
|
|
||||||
-- test vector from somewhere
|
-- test vector from somewhere
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x8000000000000000',
|
||||||
decode('80 00 00 00 00 00 00 00', 'hex'),
|
'\x010101010101010101010101010101010101010101010101',
|
||||||
decode('01 01 01 01 01 01 01 01
|
'3des-ecb/pad:none');
|
||||||
01 01 01 01 01 01 01 01
|
encrypt
|
||||||
01 01 01 01 01 01 01 01', 'hex'),
|
--------------------
|
||||||
'3des-ecb/pad:none'), 'hex');
|
\x95f8a5e5dd31d900
|
||||||
encode
|
|
||||||
------------------
|
|
||||||
95f8a5e5dd31d900
|
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- val 95 F8 A5 E5 DD 31 D9 00
|
select encrypt('', 'foo', '3des');
|
||||||
select encode( encrypt('', 'foo', '3des'), 'hex');
|
encrypt
|
||||||
encode
|
--------------------
|
||||||
------------------
|
\x752111e37a2d7ac3
|
||||||
752111e37a2d7ac3
|
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- 10 bytes key
|
-- 10 bytes key
|
||||||
select encode( encrypt('foo', '0123456789', '3des'), 'hex');
|
select encrypt('foo', '0123456789', '3des');
|
||||||
encode
|
encrypt
|
||||||
------------------
|
--------------------
|
||||||
d2fb8baa1717cb02
|
\xd2fb8baa1717cb02
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- 22 bytes key
|
-- 22 bytes key
|
||||||
select encode( encrypt('foo', '0123456789012345678901', '3des'), 'hex');
|
select encrypt('foo', '0123456789012345678901', '3des');
|
||||||
encode
|
encrypt
|
||||||
------------------
|
--------------------
|
||||||
a44360e699269817
|
\xa44360e699269817
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- decrypt
|
-- decrypt
|
||||||
select decrypt(encrypt('foo', '0123456', '3des'), '0123456', '3des');
|
select encode(decrypt(encrypt('foo', '0123456', '3des'), '0123456', '3des'), 'escape');
|
||||||
decrypt
|
encode
|
||||||
---------
|
--------
|
||||||
foo
|
foo
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- iv
|
-- iv
|
||||||
select encode(encrypt_iv('foo', '0123456', 'abcd', '3des'), 'hex');
|
select encrypt_iv('foo', '0123456', 'abcd', '3des');
|
||||||
encode
|
encrypt_iv
|
||||||
------------------
|
--------------------
|
||||||
50735067b073bb93
|
\x50735067b073bb93
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
select decrypt_iv(decode('50735067b073bb93', 'hex'), '0123456', 'abcd', '3des');
|
select encode(decrypt_iv('\x50735067b073bb93', '0123456', 'abcd', '3des'), 'escape');
|
||||||
decrypt_iv
|
encode
|
||||||
------------
|
--------
|
||||||
foo
|
foo
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- long message
|
-- long message
|
||||||
select encode(encrypt('Lets try a longer message.', '0123456789012345678901', '3des'), 'hex');
|
select encrypt('Lets try a longer message.', '0123456789012345678901', '3des');
|
||||||
encode
|
encrypt
|
||||||
------------------------------------------------------------------
|
--------------------------------------------------------------------
|
||||||
b71e3422269d0ded19468f33d65cd663c28e0871984792a7b3ba0ddcecec8d2c
|
\xb71e3422269d0ded19468f33d65cd663c28e0871984792a7b3ba0ddcecec8d2c
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
select decrypt(encrypt('Lets try a longer message.', '0123456789012345678901', '3des'), '0123456789012345678901', '3des');
|
select encode(decrypt(encrypt('Lets try a longer message.', '0123456789012345678901', '3des'), '0123456789012345678901', '3des'), 'escape');
|
||||||
decrypt
|
encode
|
||||||
----------------------------
|
----------------------------
|
||||||
Lets try a longer message.
|
Lets try a longer message.
|
||||||
(1 row)
|
(1 row)
|
||||||
|
@ -1,174 +1,141 @@
|
|||||||
--
|
--
|
||||||
-- Blowfish cipher
|
-- Blowfish cipher
|
||||||
--
|
--
|
||||||
-- ensure consistent test output regardless of the default bytea format
|
|
||||||
SET bytea_output TO escape;
|
|
||||||
-- some standard Blowfish testvalues
|
-- some standard Blowfish testvalues
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x0000000000000000', '\x0000000000000000', 'bf-ecb/pad:none');
|
||||||
decode('0000000000000000', 'hex'),
|
encrypt
|
||||||
decode('0000000000000000', 'hex'),
|
--------------------
|
||||||
'bf-ecb/pad:none'), 'hex');
|
\x4ef997456198dd78
|
||||||
encode
|
|
||||||
------------------
|
|
||||||
4ef997456198dd78
|
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\xffffffffffffffff', '\xffffffffffffffff', 'bf-ecb/pad:none');
|
||||||
decode('ffffffffffffffff', 'hex'),
|
encrypt
|
||||||
decode('ffffffffffffffff', 'hex'),
|
--------------------
|
||||||
'bf-ecb/pad:none'), 'hex');
|
\x51866fd5b85ecb8a
|
||||||
encode
|
|
||||||
------------------
|
|
||||||
51866fd5b85ecb8a
|
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x1000000000000001', '\x3000000000000000', 'bf-ecb/pad:none');
|
||||||
decode('1000000000000001', 'hex'),
|
encrypt
|
||||||
decode('3000000000000000', 'hex'),
|
--------------------
|
||||||
'bf-ecb/pad:none'), 'hex');
|
\x7d856f9a613063f2
|
||||||
encode
|
|
||||||
------------------
|
|
||||||
7d856f9a613063f2
|
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x1111111111111111', '\x1111111111111111', 'bf-ecb/pad:none');
|
||||||
decode('1111111111111111', 'hex'),
|
encrypt
|
||||||
decode('1111111111111111', 'hex'),
|
--------------------
|
||||||
'bf-ecb/pad:none'), 'hex');
|
\x2466dd878b963c9d
|
||||||
encode
|
|
||||||
------------------
|
|
||||||
2466dd878b963c9d
|
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x0123456789abcdef', '\xfedcba9876543210', 'bf-ecb/pad:none');
|
||||||
decode('0123456789abcdef', 'hex'),
|
encrypt
|
||||||
decode('fedcba9876543210', 'hex'),
|
--------------------
|
||||||
'bf-ecb/pad:none'), 'hex');
|
\x0aceab0fc6a0a28d
|
||||||
encode
|
|
||||||
------------------
|
|
||||||
0aceab0fc6a0a28d
|
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x01a1d6d039776742', '\xfedcba9876543210', 'bf-ecb/pad:none');
|
||||||
decode('01a1d6d039776742', 'hex'),
|
encrypt
|
||||||
decode('fedcba9876543210', 'hex'),
|
--------------------
|
||||||
'bf-ecb/pad:none'), 'hex');
|
\x3273b8badc9e9e15
|
||||||
encode
|
|
||||||
------------------
|
|
||||||
3273b8badc9e9e15
|
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\xffffffffffffffff', '\x0000000000000000', 'bf-ecb/pad:none');
|
||||||
decode('ffffffffffffffff', 'hex'),
|
encrypt
|
||||||
decode('0000000000000000', 'hex'),
|
--------------------
|
||||||
'bf-ecb/pad:none'), 'hex');
|
\x014933e0cdaff6e4
|
||||||
encode
|
|
||||||
------------------
|
|
||||||
014933e0cdaff6e4
|
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- setkey
|
-- setkey
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\xfedcba9876543210', '\xf0e1d2c3b4a5968778695a4b3c2d1e0f', 'bf-ecb/pad:none');
|
||||||
decode('fedcba9876543210', 'hex'),
|
encrypt
|
||||||
decode('f0e1d2c3b4a5968778695a4b3c2d1e0f', 'hex'),
|
--------------------
|
||||||
'bf-ecb/pad:none'), 'hex');
|
\x93142887ee3be15c
|
||||||
encode
|
|
||||||
------------------
|
|
||||||
93142887ee3be15c
|
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- with padding
|
-- with padding
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x01234567890123456789', '\x33443344334433443344334433443344', 'bf-ecb');
|
||||||
decode('01234567890123456789', 'hex'),
|
encrypt
|
||||||
decode('33443344334433443344334433443344', 'hex'),
|
------------------------------------
|
||||||
'bf-ecb'), 'hex');
|
\x0d04a43a20456dee5ede6ed9e4dcaaa6
|
||||||
encode
|
|
||||||
----------------------------------
|
|
||||||
0d04a43a20456dee5ede6ed9e4dcaaa6
|
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- cbc
|
-- cbc
|
||||||
-- 28 bytes key
|
-- 28 bytes key
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5',
|
||||||
decode('6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5', 'hex'),
|
'\x37363534333231204e6f77206973207468652074696d6520666f7220',
|
||||||
decode('37363534333231204e6f77206973207468652074696d6520666f7220', 'hex'),
|
'bf-cbc');
|
||||||
'bf-cbc'), 'hex');
|
encrypt
|
||||||
encode
|
--------------------------------------------------------------------
|
||||||
------------------------------------------------------------------
|
\x4f2beb748c4f689ec755edb9dc252a41b93a3786850b4c75d6a702b6a8e48825
|
||||||
4f2beb748c4f689ec755edb9dc252a41b93a3786850b4c75d6a702b6a8e48825
|
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- 29 bytes key
|
-- 29 bytes key
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5ff92cc',
|
||||||
decode('6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5ff92cc', 'hex'),
|
'\x37363534333231204e6f77206973207468652074696d6520666f722000',
|
||||||
decode('37363534333231204e6f77206973207468652074696d6520666f722000', 'hex'),
|
'bf-cbc');
|
||||||
'bf-cbc'), 'hex');
|
encrypt
|
||||||
encode
|
------------------------------------------------------------------------------------
|
||||||
----------------------------------------------------------------------------------
|
\x3ea6357a0ee7fad6d0c4b63464f2aafa40c2e91b4b7e1bba8114932fd92b5c8f111e7e50e7b2e541
|
||||||
3ea6357a0ee7fad6d0c4b63464f2aafa40c2e91b4b7e1bba8114932fd92b5c8f111e7e50e7b2e541
|
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- blowfish-448
|
-- blowfish-448
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\xfedcba9876543210',
|
||||||
decode('fedcba9876543210', 'hex'),
|
'\xf0e1d2c3b4a5968778695a4b3c2d1e0f001122334455667704689104c2fd3b2f584023641aba61761f1f1f1f0e0e0e0effffffffffffffff',
|
||||||
decode('f0e1d2c3b4a5968778695a4b3c2d1e0f001122334455667704689104c2fd3b2f584023641aba61761f1f1f1f0e0e0e0effffffffffffffff', 'hex'),
|
'bf-ecb/pad:none');
|
||||||
'bf-ecb/pad:none'), 'hex');
|
encrypt
|
||||||
encode
|
--------------------
|
||||||
------------------
|
\xc04504012e4e1f53
|
||||||
c04504012e4e1f53
|
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- result: c04504012e4e1f53
|
|
||||||
-- empty data
|
-- empty data
|
||||||
select encode(encrypt('', 'foo', 'bf'), 'hex');
|
select encrypt('', 'foo', 'bf');
|
||||||
encode
|
encrypt
|
||||||
------------------
|
--------------------
|
||||||
1871949bb2311c8e
|
\x1871949bb2311c8e
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- 10 bytes key
|
-- 10 bytes key
|
||||||
select encode(encrypt('foo', '0123456789', 'bf'), 'hex');
|
select encrypt('foo', '0123456789', 'bf');
|
||||||
encode
|
encrypt
|
||||||
------------------
|
--------------------
|
||||||
42f58af3b2c03f46
|
\x42f58af3b2c03f46
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- 22 bytes key
|
-- 22 bytes key
|
||||||
select encode(encrypt('foo', '0123456789012345678901', 'bf'), 'hex');
|
select encrypt('foo', '0123456789012345678901', 'bf');
|
||||||
encode
|
encrypt
|
||||||
------------------
|
--------------------
|
||||||
86ab6f0bc72b5f22
|
\x86ab6f0bc72b5f22
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- decrypt
|
-- decrypt
|
||||||
select decrypt(encrypt('foo', '0123456', 'bf'), '0123456', 'bf');
|
select encode(decrypt(encrypt('foo', '0123456', 'bf'), '0123456', 'bf'), 'escape');
|
||||||
decrypt
|
encode
|
||||||
---------
|
--------
|
||||||
foo
|
foo
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- iv
|
-- iv
|
||||||
select encode(encrypt_iv('foo', '0123456', 'abcd', 'bf'), 'hex');
|
select encrypt_iv('foo', '0123456', 'abcd', 'bf');
|
||||||
encode
|
encrypt_iv
|
||||||
------------------
|
--------------------
|
||||||
95c7e89322525d59
|
\x95c7e89322525d59
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
select decrypt_iv(decode('95c7e89322525d59', 'hex'), '0123456', 'abcd', 'bf');
|
select encode(decrypt_iv('\x95c7e89322525d59', '0123456', 'abcd', 'bf'), 'escape');
|
||||||
decrypt_iv
|
encode
|
||||||
------------
|
--------
|
||||||
foo
|
foo
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- long message
|
-- long message
|
||||||
select encode(encrypt('Lets try a longer message.', '0123456789', 'bf'), 'hex');
|
select encrypt('Lets try a longer message.', '0123456789', 'bf');
|
||||||
encode
|
encrypt
|
||||||
------------------------------------------------------------------
|
--------------------------------------------------------------------
|
||||||
a76059f7a1b627b5b84080d9beb337714c7a7f8b70300023e5feb6dfa6813536
|
\xa76059f7a1b627b5b84080d9beb337714c7a7f8b70300023e5feb6dfa6813536
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
select decrypt(encrypt('Lets try a longer message.', '0123456789', 'bf'), '0123456789', 'bf');
|
select encode(decrypt(encrypt('Lets try a longer message.', '0123456789', 'bf'), '0123456789', 'bf'), 'escape');
|
||||||
decrypt
|
encode
|
||||||
----------------------------
|
----------------------------
|
||||||
Lets try a longer message.
|
Lets try a longer message.
|
||||||
(1 row)
|
(1 row)
|
||||||
|
@ -1,95 +1,62 @@
|
|||||||
--
|
--
|
||||||
-- Blowfish cipher
|
-- Blowfish cipher
|
||||||
--
|
--
|
||||||
-- ensure consistent test output regardless of the default bytea format
|
|
||||||
SET bytea_output TO escape;
|
|
||||||
-- some standard Blowfish testvalues
|
-- some standard Blowfish testvalues
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x0000000000000000', '\x0000000000000000', 'bf-ecb/pad:none');
|
||||||
decode('0000000000000000', 'hex'),
|
|
||||||
decode('0000000000000000', 'hex'),
|
|
||||||
'bf-ecb/pad:none'), 'hex');
|
|
||||||
ERROR: encrypt error: Cipher cannot be initialized ?
|
ERROR: encrypt error: Cipher cannot be initialized ?
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\xffffffffffffffff', '\xffffffffffffffff', 'bf-ecb/pad:none');
|
||||||
decode('ffffffffffffffff', 'hex'),
|
|
||||||
decode('ffffffffffffffff', 'hex'),
|
|
||||||
'bf-ecb/pad:none'), 'hex');
|
|
||||||
ERROR: encrypt error: Cipher cannot be initialized ?
|
ERROR: encrypt error: Cipher cannot be initialized ?
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x1000000000000001', '\x3000000000000000', 'bf-ecb/pad:none');
|
||||||
decode('1000000000000001', 'hex'),
|
|
||||||
decode('3000000000000000', 'hex'),
|
|
||||||
'bf-ecb/pad:none'), 'hex');
|
|
||||||
ERROR: encrypt error: Cipher cannot be initialized ?
|
ERROR: encrypt error: Cipher cannot be initialized ?
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x1111111111111111', '\x1111111111111111', 'bf-ecb/pad:none');
|
||||||
decode('1111111111111111', 'hex'),
|
|
||||||
decode('1111111111111111', 'hex'),
|
|
||||||
'bf-ecb/pad:none'), 'hex');
|
|
||||||
ERROR: encrypt error: Cipher cannot be initialized ?
|
ERROR: encrypt error: Cipher cannot be initialized ?
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x0123456789abcdef', '\xfedcba9876543210', 'bf-ecb/pad:none');
|
||||||
decode('0123456789abcdef', 'hex'),
|
|
||||||
decode('fedcba9876543210', 'hex'),
|
|
||||||
'bf-ecb/pad:none'), 'hex');
|
|
||||||
ERROR: encrypt error: Cipher cannot be initialized ?
|
ERROR: encrypt error: Cipher cannot be initialized ?
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x01a1d6d039776742', '\xfedcba9876543210', 'bf-ecb/pad:none');
|
||||||
decode('01a1d6d039776742', 'hex'),
|
|
||||||
decode('fedcba9876543210', 'hex'),
|
|
||||||
'bf-ecb/pad:none'), 'hex');
|
|
||||||
ERROR: encrypt error: Cipher cannot be initialized ?
|
ERROR: encrypt error: Cipher cannot be initialized ?
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\xffffffffffffffff', '\x0000000000000000', 'bf-ecb/pad:none');
|
||||||
decode('ffffffffffffffff', 'hex'),
|
|
||||||
decode('0000000000000000', 'hex'),
|
|
||||||
'bf-ecb/pad:none'), 'hex');
|
|
||||||
ERROR: encrypt error: Cipher cannot be initialized ?
|
ERROR: encrypt error: Cipher cannot be initialized ?
|
||||||
-- setkey
|
-- setkey
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\xfedcba9876543210', '\xf0e1d2c3b4a5968778695a4b3c2d1e0f', 'bf-ecb/pad:none');
|
||||||
decode('fedcba9876543210', 'hex'),
|
|
||||||
decode('f0e1d2c3b4a5968778695a4b3c2d1e0f', 'hex'),
|
|
||||||
'bf-ecb/pad:none'), 'hex');
|
|
||||||
ERROR: encrypt error: Cipher cannot be initialized ?
|
ERROR: encrypt error: Cipher cannot be initialized ?
|
||||||
-- with padding
|
-- with padding
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x01234567890123456789', '\x33443344334433443344334433443344', 'bf-ecb');
|
||||||
decode('01234567890123456789', 'hex'),
|
|
||||||
decode('33443344334433443344334433443344', 'hex'),
|
|
||||||
'bf-ecb'), 'hex');
|
|
||||||
ERROR: encrypt error: Cipher cannot be initialized ?
|
ERROR: encrypt error: Cipher cannot be initialized ?
|
||||||
-- cbc
|
-- cbc
|
||||||
-- 28 bytes key
|
-- 28 bytes key
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5',
|
||||||
decode('6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5', 'hex'),
|
'\x37363534333231204e6f77206973207468652074696d6520666f7220',
|
||||||
decode('37363534333231204e6f77206973207468652074696d6520666f7220', 'hex'),
|
'bf-cbc');
|
||||||
'bf-cbc'), 'hex');
|
|
||||||
ERROR: encrypt error: Key was too big
|
ERROR: encrypt error: Key was too big
|
||||||
-- 29 bytes key
|
-- 29 bytes key
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5ff92cc',
|
||||||
decode('6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5ff92cc', 'hex'),
|
'\x37363534333231204e6f77206973207468652074696d6520666f722000',
|
||||||
decode('37363534333231204e6f77206973207468652074696d6520666f722000', 'hex'),
|
'bf-cbc');
|
||||||
'bf-cbc'), 'hex');
|
|
||||||
ERROR: encrypt error: Key was too big
|
ERROR: encrypt error: Key was too big
|
||||||
-- blowfish-448
|
-- blowfish-448
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\xfedcba9876543210',
|
||||||
decode('fedcba9876543210', 'hex'),
|
'\xf0e1d2c3b4a5968778695a4b3c2d1e0f001122334455667704689104c2fd3b2f584023641aba61761f1f1f1f0e0e0e0effffffffffffffff',
|
||||||
decode('f0e1d2c3b4a5968778695a4b3c2d1e0f001122334455667704689104c2fd3b2f584023641aba61761f1f1f1f0e0e0e0effffffffffffffff', 'hex'),
|
'bf-ecb/pad:none');
|
||||||
'bf-ecb/pad:none'), 'hex');
|
|
||||||
ERROR: encrypt error: Key was too big
|
ERROR: encrypt error: Key was too big
|
||||||
-- result: c04504012e4e1f53
|
|
||||||
-- empty data
|
-- empty data
|
||||||
select encode(encrypt('', 'foo', 'bf'), 'hex');
|
select encrypt('', 'foo', 'bf');
|
||||||
ERROR: encrypt error: Cipher cannot be initialized ?
|
ERROR: encrypt error: Cipher cannot be initialized ?
|
||||||
-- 10 bytes key
|
-- 10 bytes key
|
||||||
select encode(encrypt('foo', '0123456789', 'bf'), 'hex');
|
select encrypt('foo', '0123456789', 'bf');
|
||||||
ERROR: encrypt error: Cipher cannot be initialized ?
|
ERROR: encrypt error: Cipher cannot be initialized ?
|
||||||
-- 22 bytes key
|
-- 22 bytes key
|
||||||
select encode(encrypt('foo', '0123456789012345678901', 'bf'), 'hex');
|
select encrypt('foo', '0123456789012345678901', 'bf');
|
||||||
ERROR: encrypt error: Key was too big
|
ERROR: encrypt error: Key was too big
|
||||||
-- decrypt
|
-- decrypt
|
||||||
select decrypt(encrypt('foo', '0123456', 'bf'), '0123456', 'bf');
|
select encode(decrypt(encrypt('foo', '0123456', 'bf'), '0123456', 'bf'), 'escape');
|
||||||
ERROR: encrypt error: Cipher cannot be initialized ?
|
ERROR: encrypt error: Cipher cannot be initialized ?
|
||||||
-- iv
|
-- iv
|
||||||
select encode(encrypt_iv('foo', '0123456', 'abcd', 'bf'), 'hex');
|
select encrypt_iv('foo', '0123456', 'abcd', 'bf');
|
||||||
ERROR: encrypt_iv error: Cipher cannot be initialized ?
|
ERROR: encrypt_iv error: Cipher cannot be initialized ?
|
||||||
select decrypt_iv(decode('95c7e89322525d59', 'hex'), '0123456', 'abcd', 'bf');
|
select encode(decrypt_iv('\x95c7e89322525d59', '0123456', 'abcd', 'bf'), 'escape');
|
||||||
ERROR: decrypt_iv error: Cipher cannot be initialized ?
|
ERROR: decrypt_iv error: Cipher cannot be initialized ?
|
||||||
-- long message
|
-- long message
|
||||||
select encode(encrypt('Lets try a longer message.', '0123456789', 'bf'), 'hex');
|
select encrypt('Lets try a longer message.', '0123456789', 'bf');
|
||||||
ERROR: encrypt error: Cipher cannot be initialized ?
|
ERROR: encrypt error: Cipher cannot be initialized ?
|
||||||
select decrypt(encrypt('Lets try a longer message.', '0123456789', 'bf'), '0123456789', 'bf');
|
select encode(decrypt(encrypt('Lets try a longer message.', '0123456789', 'bf'), '0123456789', 'bf'), 'escape');
|
||||||
ERROR: encrypt error: Cipher cannot be initialized ?
|
ERROR: encrypt error: Cipher cannot be initialized ?
|
||||||
|
@ -1,87 +1,72 @@
|
|||||||
--
|
--
|
||||||
-- Cast5 cipher
|
-- Cast5 cipher
|
||||||
--
|
--
|
||||||
-- ensure consistent test output regardless of the default bytea format
|
|
||||||
SET bytea_output TO escape;
|
|
||||||
-- test vectors from RFC2144
|
-- test vectors from RFC2144
|
||||||
-- 128 bit key
|
-- 128 bit key
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x0123456789ABCDEF', '\x0123456712345678234567893456789A', 'cast5-ecb/pad:none');
|
||||||
decode('01 23 45 67 89 AB CD EF', 'hex'),
|
encrypt
|
||||||
decode('01 23 45 67 12 34 56 78 23 45 67 89 34 56 78 9A', 'hex'),
|
--------------------
|
||||||
'cast5-ecb/pad:none'), 'hex');
|
\x238b4fe5847e44b2
|
||||||
encode
|
|
||||||
------------------
|
|
||||||
238b4fe5847e44b2
|
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- result: 23 8B 4F E5 84 7E 44 B2
|
|
||||||
-- 80 bit key
|
-- 80 bit key
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x0123456789ABCDEF', '\x01234567123456782345', 'cast5-ecb/pad:none');
|
||||||
decode('01 23 45 67 89 AB CD EF', 'hex'),
|
encrypt
|
||||||
decode('01 23 45 67 12 34 56 78 23 45', 'hex'),
|
--------------------
|
||||||
'cast5-ecb/pad:none'), 'hex');
|
\xeb6a711a2c02271b
|
||||||
encode
|
|
||||||
------------------
|
|
||||||
eb6a711a2c02271b
|
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- result: EB 6A 71 1A 2C 02 27 1B
|
|
||||||
-- 40 bit key
|
-- 40 bit key
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x0123456789ABCDEF', '\x0123456712', 'cast5-ecb/pad:none');
|
||||||
decode('01 23 45 67 89 AB CD EF', 'hex'),
|
encrypt
|
||||||
decode('01 23 45 67 12', 'hex'),
|
--------------------
|
||||||
'cast5-ecb/pad:none'), 'hex');
|
\x7ac816d16e9b302e
|
||||||
encode
|
|
||||||
------------------
|
|
||||||
7ac816d16e9b302e
|
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- result: 7A C8 16 D1 6E 9B 30 2E
|
|
||||||
-- cbc
|
-- cbc
|
||||||
-- empty data
|
-- empty data
|
||||||
select encode( encrypt('', 'foo', 'cast5'), 'hex');
|
select encrypt('', 'foo', 'cast5');
|
||||||
encode
|
encrypt
|
||||||
------------------
|
--------------------
|
||||||
a48bd1aabde4de10
|
\xa48bd1aabde4de10
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- 10 bytes key
|
-- 10 bytes key
|
||||||
select encode( encrypt('foo', '0123456789', 'cast5'), 'hex');
|
select encrypt('foo', '0123456789', 'cast5');
|
||||||
encode
|
encrypt
|
||||||
------------------
|
--------------------
|
||||||
b07f19255e60cb6d
|
\xb07f19255e60cb6d
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- decrypt
|
-- decrypt
|
||||||
select decrypt(encrypt('foo', '0123456', 'cast5'), '0123456', 'cast5');
|
select encode(decrypt(encrypt('foo', '0123456', 'cast5'), '0123456', 'cast5'), 'escape');
|
||||||
decrypt
|
encode
|
||||||
---------
|
--------
|
||||||
foo
|
foo
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- iv
|
-- iv
|
||||||
select encode(encrypt_iv('foo', '0123456', 'abcd', 'cast5'), 'hex');
|
select encrypt_iv('foo', '0123456', 'abcd', 'cast5');
|
||||||
encode
|
encrypt_iv
|
||||||
------------------
|
--------------------
|
||||||
384a970695ce016a
|
\x384a970695ce016a
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
select decrypt_iv(decode('384a970695ce016a', 'hex'),
|
select encode(decrypt_iv('\x384a970695ce016a', '0123456', 'abcd', 'cast5'), 'escape');
|
||||||
'0123456', 'abcd', 'cast5');
|
encode
|
||||||
decrypt_iv
|
--------
|
||||||
------------
|
|
||||||
foo
|
foo
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- long message
|
-- long message
|
||||||
select encode(encrypt('Lets try a longer message.', '0123456789', 'cast5'), 'hex');
|
select encrypt('Lets try a longer message.', '0123456789', 'cast5');
|
||||||
encode
|
encrypt
|
||||||
------------------------------------------------------------------
|
--------------------------------------------------------------------
|
||||||
04fcffc91533e1505dadcb10766d9fed0937818e663e402384e049942ba60fff
|
\x04fcffc91533e1505dadcb10766d9fed0937818e663e402384e049942ba60fff
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
select decrypt(encrypt('Lets try a longer message.', '0123456789', 'cast5'), '0123456789', 'cast5');
|
select encode(decrypt(encrypt('Lets try a longer message.', '0123456789', 'cast5'), '0123456789', 'cast5'), 'escape');
|
||||||
decrypt
|
encode
|
||||||
----------------------------
|
----------------------------
|
||||||
Lets try a longer message.
|
Lets try a longer message.
|
||||||
(1 row)
|
(1 row)
|
||||||
|
@ -1,48 +1,33 @@
|
|||||||
--
|
--
|
||||||
-- Cast5 cipher
|
-- Cast5 cipher
|
||||||
--
|
--
|
||||||
-- ensure consistent test output regardless of the default bytea format
|
|
||||||
SET bytea_output TO escape;
|
|
||||||
-- test vectors from RFC2144
|
-- test vectors from RFC2144
|
||||||
-- 128 bit key
|
-- 128 bit key
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x0123456789ABCDEF', '\x0123456712345678234567893456789A', 'cast5-ecb/pad:none');
|
||||||
decode('01 23 45 67 89 AB CD EF', 'hex'),
|
|
||||||
decode('01 23 45 67 12 34 56 78 23 45 67 89 34 56 78 9A', 'hex'),
|
|
||||||
'cast5-ecb/pad:none'), 'hex');
|
|
||||||
ERROR: encrypt error: Cipher cannot be initialized ?
|
ERROR: encrypt error: Cipher cannot be initialized ?
|
||||||
-- result: 23 8B 4F E5 84 7E 44 B2
|
|
||||||
-- 80 bit key
|
-- 80 bit key
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x0123456789ABCDEF', '\x01234567123456782345', 'cast5-ecb/pad:none');
|
||||||
decode('01 23 45 67 89 AB CD EF', 'hex'),
|
|
||||||
decode('01 23 45 67 12 34 56 78 23 45', 'hex'),
|
|
||||||
'cast5-ecb/pad:none'), 'hex');
|
|
||||||
ERROR: encrypt error: Cipher cannot be initialized ?
|
ERROR: encrypt error: Cipher cannot be initialized ?
|
||||||
-- result: EB 6A 71 1A 2C 02 27 1B
|
|
||||||
-- 40 bit key
|
-- 40 bit key
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x0123456789ABCDEF', '\x0123456712', 'cast5-ecb/pad:none');
|
||||||
decode('01 23 45 67 89 AB CD EF', 'hex'),
|
|
||||||
decode('01 23 45 67 12', 'hex'),
|
|
||||||
'cast5-ecb/pad:none'), 'hex');
|
|
||||||
ERROR: encrypt error: Cipher cannot be initialized ?
|
ERROR: encrypt error: Cipher cannot be initialized ?
|
||||||
-- result: 7A C8 16 D1 6E 9B 30 2E
|
|
||||||
-- cbc
|
-- cbc
|
||||||
-- empty data
|
-- empty data
|
||||||
select encode( encrypt('', 'foo', 'cast5'), 'hex');
|
select encrypt('', 'foo', 'cast5');
|
||||||
ERROR: encrypt error: Cipher cannot be initialized ?
|
ERROR: encrypt error: Cipher cannot be initialized ?
|
||||||
-- 10 bytes key
|
-- 10 bytes key
|
||||||
select encode( encrypt('foo', '0123456789', 'cast5'), 'hex');
|
select encrypt('foo', '0123456789', 'cast5');
|
||||||
ERROR: encrypt error: Cipher cannot be initialized ?
|
ERROR: encrypt error: Cipher cannot be initialized ?
|
||||||
-- decrypt
|
-- decrypt
|
||||||
select decrypt(encrypt('foo', '0123456', 'cast5'), '0123456', 'cast5');
|
select encode(decrypt(encrypt('foo', '0123456', 'cast5'), '0123456', 'cast5'), 'escape');
|
||||||
ERROR: encrypt error: Cipher cannot be initialized ?
|
ERROR: encrypt error: Cipher cannot be initialized ?
|
||||||
-- iv
|
-- iv
|
||||||
select encode(encrypt_iv('foo', '0123456', 'abcd', 'cast5'), 'hex');
|
select encrypt_iv('foo', '0123456', 'abcd', 'cast5');
|
||||||
ERROR: encrypt_iv error: Cipher cannot be initialized ?
|
ERROR: encrypt_iv error: Cipher cannot be initialized ?
|
||||||
select decrypt_iv(decode('384a970695ce016a', 'hex'),
|
select encode(decrypt_iv('\x384a970695ce016a', '0123456', 'abcd', 'cast5'), 'escape');
|
||||||
'0123456', 'abcd', 'cast5');
|
|
||||||
ERROR: decrypt_iv error: Cipher cannot be initialized ?
|
ERROR: decrypt_iv error: Cipher cannot be initialized ?
|
||||||
-- long message
|
-- long message
|
||||||
select encode(encrypt('Lets try a longer message.', '0123456789', 'cast5'), 'hex');
|
select encrypt('Lets try a longer message.', '0123456789', 'cast5');
|
||||||
ERROR: encrypt error: Cipher cannot be initialized ?
|
ERROR: encrypt error: Cipher cannot be initialized ?
|
||||||
select decrypt(encrypt('Lets try a longer message.', '0123456789', 'cast5'), '0123456789', 'cast5');
|
select encode(decrypt(encrypt('Lets try a longer message.', '0123456789', 'cast5'), '0123456789', 'cast5'), 'escape');
|
||||||
ERROR: encrypt error: Cipher cannot be initialized ?
|
ERROR: encrypt error: Cipher cannot be initialized ?
|
||||||
|
@ -1,62 +1,57 @@
|
|||||||
--
|
--
|
||||||
-- DES cipher
|
-- DES cipher
|
||||||
--
|
--
|
||||||
-- ensure consistent test output regardless of the default bytea format
|
|
||||||
SET bytea_output TO escape;
|
|
||||||
-- no official test vectors atm
|
-- no official test vectors atm
|
||||||
-- from blowfish.sql
|
-- from blowfish.sql
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x0123456789abcdef', '\xfedcba9876543210', 'des-ecb/pad:none');
|
||||||
decode('0123456789abcdef', 'hex'),
|
encrypt
|
||||||
decode('fedcba9876543210', 'hex'),
|
--------------------
|
||||||
'des-ecb/pad:none'), 'hex');
|
\xed39d950fa74bcc4
|
||||||
encode
|
|
||||||
------------------
|
|
||||||
ed39d950fa74bcc4
|
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- empty data
|
-- empty data
|
||||||
select encode( encrypt('', 'foo', 'des'), 'hex');
|
select encrypt('', 'foo', 'des');
|
||||||
encode
|
encrypt
|
||||||
------------------
|
--------------------
|
||||||
752111e37a2d7ac3
|
\x752111e37a2d7ac3
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- 8 bytes key
|
-- 8 bytes key
|
||||||
select encode( encrypt('foo', '01234589', 'des'), 'hex');
|
select encrypt('foo', '01234589', 'des');
|
||||||
encode
|
encrypt
|
||||||
------------------
|
--------------------
|
||||||
dec0f9c602b647a8
|
\xdec0f9c602b647a8
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- decrypt
|
-- decrypt
|
||||||
select decrypt(encrypt('foo', '0123456', 'des'), '0123456', 'des');
|
select encode(decrypt(encrypt('foo', '0123456', 'des'), '0123456', 'des'), 'escape');
|
||||||
decrypt
|
encode
|
||||||
---------
|
--------
|
||||||
foo
|
foo
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- iv
|
-- iv
|
||||||
select encode(encrypt_iv('foo', '0123456', 'abcd', 'des'), 'hex');
|
select encrypt_iv('foo', '0123456', 'abcd', 'des');
|
||||||
encode
|
encrypt_iv
|
||||||
------------------
|
--------------------
|
||||||
50735067b073bb93
|
\x50735067b073bb93
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
select decrypt_iv(decode('50735067b073bb93', 'hex'), '0123456', 'abcd', 'des');
|
select encode(decrypt_iv('\x50735067b073bb93', '0123456', 'abcd', 'des'), 'escape');
|
||||||
decrypt_iv
|
encode
|
||||||
------------
|
--------
|
||||||
foo
|
foo
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- long message
|
-- long message
|
||||||
select encode(encrypt('Lets try a longer message.', '01234567', 'des'), 'hex');
|
select encrypt('Lets try a longer message.', '01234567', 'des');
|
||||||
encode
|
encrypt
|
||||||
------------------------------------------------------------------
|
--------------------------------------------------------------------
|
||||||
5ad146043e5f30967e06a0fcbae602daf4ff2a5fd0ed12d6c5913cf85f1e36ca
|
\x5ad146043e5f30967e06a0fcbae602daf4ff2a5fd0ed12d6c5913cf85f1e36ca
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
select decrypt(encrypt('Lets try a longer message.', '01234567', 'des'), '01234567', 'des');
|
select encode(decrypt(encrypt('Lets try a longer message.', '01234567', 'des'), '01234567', 'des'), 'escape');
|
||||||
decrypt
|
encode
|
||||||
----------------------------
|
----------------------------
|
||||||
Lets try a longer message.
|
Lets try a longer message.
|
||||||
(1 row)
|
(1 row)
|
||||||
|
@ -1,31 +1,26 @@
|
|||||||
--
|
--
|
||||||
-- DES cipher
|
-- DES cipher
|
||||||
--
|
--
|
||||||
-- ensure consistent test output regardless of the default bytea format
|
|
||||||
SET bytea_output TO escape;
|
|
||||||
-- no official test vectors atm
|
-- no official test vectors atm
|
||||||
-- from blowfish.sql
|
-- from blowfish.sql
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x0123456789abcdef', '\xfedcba9876543210', 'des-ecb/pad:none');
|
||||||
decode('0123456789abcdef', 'hex'),
|
|
||||||
decode('fedcba9876543210', 'hex'),
|
|
||||||
'des-ecb/pad:none'), 'hex');
|
|
||||||
ERROR: encrypt error: Cipher cannot be initialized ?
|
ERROR: encrypt error: Cipher cannot be initialized ?
|
||||||
-- empty data
|
-- empty data
|
||||||
select encode( encrypt('', 'foo', 'des'), 'hex');
|
select encrypt('', 'foo', 'des');
|
||||||
ERROR: encrypt error: Cipher cannot be initialized ?
|
ERROR: encrypt error: Cipher cannot be initialized ?
|
||||||
-- 8 bytes key
|
-- 8 bytes key
|
||||||
select encode( encrypt('foo', '01234589', 'des'), 'hex');
|
select encrypt('foo', '01234589', 'des');
|
||||||
ERROR: encrypt error: Cipher cannot be initialized ?
|
ERROR: encrypt error: Cipher cannot be initialized ?
|
||||||
-- decrypt
|
-- decrypt
|
||||||
select decrypt(encrypt('foo', '0123456', 'des'), '0123456', 'des');
|
select encode(decrypt(encrypt('foo', '0123456', 'des'), '0123456', 'des'), 'escape');
|
||||||
ERROR: encrypt error: Cipher cannot be initialized ?
|
ERROR: encrypt error: Cipher cannot be initialized ?
|
||||||
-- iv
|
-- iv
|
||||||
select encode(encrypt_iv('foo', '0123456', 'abcd', 'des'), 'hex');
|
select encrypt_iv('foo', '0123456', 'abcd', 'des');
|
||||||
ERROR: encrypt_iv error: Cipher cannot be initialized ?
|
ERROR: encrypt_iv error: Cipher cannot be initialized ?
|
||||||
select decrypt_iv(decode('50735067b073bb93', 'hex'), '0123456', 'abcd', 'des');
|
select encode(decrypt_iv('\x50735067b073bb93', '0123456', 'abcd', 'des'), 'escape');
|
||||||
ERROR: decrypt_iv error: Cipher cannot be initialized ?
|
ERROR: decrypt_iv error: Cipher cannot be initialized ?
|
||||||
-- long message
|
-- long message
|
||||||
select encode(encrypt('Lets try a longer message.', '01234567', 'des'), 'hex');
|
select encrypt('Lets try a longer message.', '01234567', 'des');
|
||||||
ERROR: encrypt error: Cipher cannot be initialized ?
|
ERROR: encrypt error: Cipher cannot be initialized ?
|
||||||
select decrypt(encrypt('Lets try a longer message.', '01234567', 'des'), '01234567', 'des');
|
select encode(decrypt(encrypt('Lets try a longer message.', '01234567', 'des'), '01234567', 'des'), 'escape');
|
||||||
ERROR: encrypt error: Cipher cannot be initialized ?
|
ERROR: encrypt error: Cipher cannot be initialized ?
|
||||||
|
@ -1,72 +1,72 @@
|
|||||||
--
|
--
|
||||||
-- HMAC-MD5
|
-- HMAC-MD5
|
||||||
--
|
--
|
||||||
SELECT encode(hmac(
|
SELECT hmac(
|
||||||
'Hi There',
|
'Hi There',
|
||||||
decode('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b', 'hex'),
|
'\x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b'::bytea,
|
||||||
'md5'), 'hex');
|
'md5');
|
||||||
encode
|
hmac
|
||||||
----------------------------------
|
------------------------------------
|
||||||
9294727a3638bb1c13f48ef8158bfc9d
|
\x9294727a3638bb1c13f48ef8158bfc9d
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- 2
|
-- 2
|
||||||
SELECT encode(hmac(
|
SELECT hmac(
|
||||||
'Jefe',
|
'Jefe',
|
||||||
'what do ya want for nothing?',
|
'what do ya want for nothing?',
|
||||||
'md5'), 'hex');
|
'md5');
|
||||||
encode
|
hmac
|
||||||
----------------------------------
|
------------------------------------
|
||||||
813aead7c4a34bff01a16d61368e7c13
|
\x813aead7c4a34bff01a16d61368e7c13
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- 3
|
-- 3
|
||||||
SELECT encode(hmac(
|
SELECT hmac(
|
||||||
decode('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd', 'hex'),
|
'\xdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd'::bytea,
|
||||||
decode('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'hex'),
|
'\xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'::bytea,
|
||||||
'md5'), 'hex');
|
'md5');
|
||||||
encode
|
hmac
|
||||||
----------------------------------
|
------------------------------------
|
||||||
56be34521d144c88dbb8c733f0e8b3f6
|
\x56be34521d144c88dbb8c733f0e8b3f6
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- 4
|
-- 4
|
||||||
SELECT encode(hmac(
|
SELECT hmac(
|
||||||
decode('cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd', 'hex'),
|
'\xcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd'::bytea,
|
||||||
decode('0102030405060708090a0b0c0d0e0f10111213141516171819', 'hex'),
|
'\x0102030405060708090a0b0c0d0e0f10111213141516171819'::bytea,
|
||||||
'md5'), 'hex');
|
'md5');
|
||||||
encode
|
hmac
|
||||||
----------------------------------
|
------------------------------------
|
||||||
697eaf0aca3a3aea3a75164746ffaa79
|
\x697eaf0aca3a3aea3a75164746ffaa79
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- 5
|
-- 5
|
||||||
SELECT encode(hmac(
|
SELECT hmac(
|
||||||
'Test With Truncation',
|
'Test With Truncation',
|
||||||
decode('0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c', 'hex'),
|
'\x0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c'::bytea,
|
||||||
'md5'), 'hex');
|
'md5');
|
||||||
encode
|
hmac
|
||||||
----------------------------------
|
------------------------------------
|
||||||
56461ef2342edc00f9bab995690efd4c
|
\x56461ef2342edc00f9bab995690efd4c
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- 6
|
-- 6
|
||||||
SELECT encode(hmac(
|
SELECT hmac(
|
||||||
'Test Using Larger Than Block-Size Key - Hash Key First',
|
'Test Using Larger Than Block-Size Key - Hash Key First',
|
||||||
decode('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'hex'),
|
'\xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'::bytea,
|
||||||
'md5'), 'hex');
|
'md5');
|
||||||
encode
|
hmac
|
||||||
----------------------------------
|
------------------------------------
|
||||||
6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd
|
\x6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- 7
|
-- 7
|
||||||
SELECT encode(hmac(
|
SELECT hmac(
|
||||||
'Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data',
|
'Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data',
|
||||||
decode('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'hex'),
|
'\xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'::bytea,
|
||||||
'md5'), 'hex');
|
'md5');
|
||||||
encode
|
hmac
|
||||||
----------------------------------
|
------------------------------------
|
||||||
6f630fad67cda0ee1fb1f562db3aa53e
|
\x6f630fad67cda0ee1fb1f562db3aa53e
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
@ -1,72 +1,72 @@
|
|||||||
--
|
--
|
||||||
-- HMAC-SHA1
|
-- HMAC-SHA1
|
||||||
--
|
--
|
||||||
SELECT encode(hmac(
|
SELECT hmac(
|
||||||
'Hi There',
|
'Hi There',
|
||||||
decode('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b', 'hex'),
|
'\x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b'::bytea,
|
||||||
'sha1'), 'hex');
|
'sha1');
|
||||||
encode
|
hmac
|
||||||
------------------------------------------
|
--------------------------------------------
|
||||||
675b0b3a1b4ddf4e124872da6c2f632bfed957e9
|
\x675b0b3a1b4ddf4e124872da6c2f632bfed957e9
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- 2
|
-- 2
|
||||||
SELECT encode(hmac(
|
SELECT hmac(
|
||||||
'Jefe',
|
'Jefe',
|
||||||
'what do ya want for nothing?',
|
'what do ya want for nothing?',
|
||||||
'sha1'), 'hex');
|
'sha1');
|
||||||
encode
|
hmac
|
||||||
------------------------------------------
|
--------------------------------------------
|
||||||
156d4c35468a0339f3fa57a067bf47f814eb7a57
|
\x156d4c35468a0339f3fa57a067bf47f814eb7a57
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- 3
|
-- 3
|
||||||
SELECT encode(hmac(
|
SELECT hmac(
|
||||||
decode('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd', 'hex'),
|
'\xdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd'::bytea,
|
||||||
decode('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'hex'),
|
'\xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'::bytea,
|
||||||
'sha1'), 'hex');
|
'sha1');
|
||||||
encode
|
hmac
|
||||||
------------------------------------------
|
--------------------------------------------
|
||||||
d730594d167e35d5956fd8003d0db3d3f46dc7bb
|
\xd730594d167e35d5956fd8003d0db3d3f46dc7bb
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- 4
|
-- 4
|
||||||
SELECT encode(hmac(
|
SELECT hmac(
|
||||||
decode('cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd', 'hex'),
|
'\xcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd'::bytea,
|
||||||
decode('0102030405060708090a0b0c0d0e0f10111213141516171819', 'hex'),
|
'\x0102030405060708090a0b0c0d0e0f10111213141516171819'::bytea,
|
||||||
'sha1'), 'hex');
|
'sha1');
|
||||||
encode
|
hmac
|
||||||
------------------------------------------
|
--------------------------------------------
|
||||||
4c9007f4026250c6bc8414f9bf50c86c2d7235da
|
\x4c9007f4026250c6bc8414f9bf50c86c2d7235da
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- 5
|
-- 5
|
||||||
SELECT encode(hmac(
|
SELECT hmac(
|
||||||
'Test With Truncation',
|
'Test With Truncation',
|
||||||
decode('0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c', 'hex'),
|
'\x0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c'::bytea,
|
||||||
'sha1'), 'hex');
|
'sha1');
|
||||||
encode
|
hmac
|
||||||
------------------------------------------
|
--------------------------------------------
|
||||||
37268b7e21e84da5720c53c4ba03ad1104039fa7
|
\x37268b7e21e84da5720c53c4ba03ad1104039fa7
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- 6
|
-- 6
|
||||||
SELECT encode(hmac(
|
SELECT hmac(
|
||||||
'Test Using Larger Than Block-Size Key - Hash Key First',
|
'Test Using Larger Than Block-Size Key - Hash Key First',
|
||||||
decode('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'hex'),
|
'\xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'::bytea,
|
||||||
'sha1'), 'hex');
|
'sha1');
|
||||||
encode
|
hmac
|
||||||
------------------------------------------
|
--------------------------------------------
|
||||||
aa4ae5e15272d00e95705637ce8a3b55ed402112
|
\xaa4ae5e15272d00e95705637ce8a3b55ed402112
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- 7
|
-- 7
|
||||||
SELECT encode(hmac(
|
SELECT hmac(
|
||||||
'Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data',
|
'Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data',
|
||||||
decode('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'hex'),
|
'\xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'::bytea,
|
||||||
'sha1'), 'hex');
|
'sha1');
|
||||||
encode
|
hmac
|
||||||
------------------------------------------
|
--------------------------------------------
|
||||||
e8e99d0f45237d786d6bbaa7965c7808bbff1a91
|
\xe8e99d0f45237d786d6bbaa7965c7808bbff1a91
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
@ -2,21 +2,6 @@
|
|||||||
-- init pgcrypto
|
-- init pgcrypto
|
||||||
--
|
--
|
||||||
CREATE EXTENSION pgcrypto;
|
CREATE EXTENSION pgcrypto;
|
||||||
-- ensure consistent test output regardless of the default bytea format
|
|
||||||
SET bytea_output TO escape;
|
|
||||||
-- check for encoding fn's
|
|
||||||
SELECT encode('foo', 'hex');
|
|
||||||
encode
|
|
||||||
--------
|
|
||||||
666f6f
|
|
||||||
(1 row)
|
|
||||||
|
|
||||||
SELECT decode('666f6f', 'hex');
|
|
||||||
decode
|
|
||||||
--------
|
|
||||||
foo
|
|
||||||
(1 row)
|
|
||||||
|
|
||||||
-- check error handling
|
-- check error handling
|
||||||
select gen_salt('foo');
|
select gen_salt('foo');
|
||||||
ERROR: gen_salt: Unknown salt algorithm
|
ERROR: gen_salt: Unknown salt algorithm
|
||||||
|
@ -1,45 +1,45 @@
|
|||||||
--
|
--
|
||||||
-- MD5 message digest
|
-- MD5 message digest
|
||||||
--
|
--
|
||||||
SELECT encode(digest('', 'md5'), 'hex');
|
SELECT digest('', 'md5');
|
||||||
encode
|
digest
|
||||||
----------------------------------
|
------------------------------------
|
||||||
d41d8cd98f00b204e9800998ecf8427e
|
\xd41d8cd98f00b204e9800998ecf8427e
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(digest('a', 'md5'), 'hex');
|
SELECT digest('a', 'md5');
|
||||||
encode
|
digest
|
||||||
----------------------------------
|
------------------------------------
|
||||||
0cc175b9c0f1b6a831c399e269772661
|
\x0cc175b9c0f1b6a831c399e269772661
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(digest('abc', 'md5'), 'hex');
|
SELECT digest('abc', 'md5');
|
||||||
encode
|
digest
|
||||||
----------------------------------
|
------------------------------------
|
||||||
900150983cd24fb0d6963f7d28e17f72
|
\x900150983cd24fb0d6963f7d28e17f72
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(digest('message digest', 'md5'), 'hex');
|
SELECT digest('message digest', 'md5');
|
||||||
encode
|
digest
|
||||||
----------------------------------
|
------------------------------------
|
||||||
f96b697d7cb7938d525a2f31aaf161d0
|
\xf96b697d7cb7938d525a2f31aaf161d0
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(digest('abcdefghijklmnopqrstuvwxyz', 'md5'), 'hex');
|
SELECT digest('abcdefghijklmnopqrstuvwxyz', 'md5');
|
||||||
encode
|
digest
|
||||||
----------------------------------
|
------------------------------------
|
||||||
c3fcd3d76192e4007dfb496cca67e13b
|
\xc3fcd3d76192e4007dfb496cca67e13b
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(digest('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', 'md5'), 'hex');
|
SELECT digest('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', 'md5');
|
||||||
encode
|
digest
|
||||||
----------------------------------
|
------------------------------------
|
||||||
d174ab98d277d9f5a5611c2c9f419d9f
|
\xd174ab98d277d9f5a5611c2c9f419d9f
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(digest('12345678901234567890123456789012345678901234567890123456789012345678901234567890', 'md5'), 'hex');
|
SELECT digest('12345678901234567890123456789012345678901234567890123456789012345678901234567890', 'md5');
|
||||||
encode
|
digest
|
||||||
----------------------------------
|
------------------------------------
|
||||||
57edf4a22be3c955ac49da2e2107b67a
|
\x57edf4a22be3c955ac49da2e2107b67a
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
--
|
--
|
||||||
-- PGP Armor
|
-- PGP Armor
|
||||||
--
|
--
|
||||||
-- ensure consistent test output regardless of the default bytea format
|
|
||||||
SET bytea_output TO escape;
|
|
||||||
select armor('');
|
select armor('');
|
||||||
armor
|
armor
|
||||||
-----------------------------
|
-----------------------------
|
||||||
@ -24,15 +22,15 @@ select armor('test');
|
|||||||
|
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
select dearmor(armor(''));
|
select encode(dearmor(armor('')), 'escape');
|
||||||
dearmor
|
encode
|
||||||
---------
|
--------
|
||||||
|
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
select dearmor(armor('zooka'));
|
select encode(dearmor(armor('zooka')), 'escape');
|
||||||
dearmor
|
encode
|
||||||
---------
|
--------
|
||||||
zooka
|
zooka
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
@ -50,7 +48,7 @@ select armor('0123456789abcdef0123456789abcdef0123456789abcdef
|
|||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- lots formatting
|
-- lots formatting
|
||||||
select dearmor(' a pgp msg:
|
select encode(dearmor(' a pgp msg:
|
||||||
|
|
||||||
-----BEGIN PGP MESSAGE-----
|
-----BEGIN PGP MESSAGE-----
|
||||||
Comment: Some junk
|
Comment: Some junk
|
||||||
@ -59,14 +57,14 @@ em9va2E=
|
|||||||
|
|
||||||
=D5cR
|
=D5cR
|
||||||
|
|
||||||
-----END PGP MESSAGE-----');
|
-----END PGP MESSAGE-----'), 'escape');
|
||||||
dearmor
|
encode
|
||||||
---------
|
--------
|
||||||
zooka
|
zooka
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- lots messages
|
-- lots messages
|
||||||
select dearmor('
|
select encode(dearmor('
|
||||||
wrong packet:
|
wrong packet:
|
||||||
-----BEGIN PGP MESSAGE-----
|
-----BEGIN PGP MESSAGE-----
|
||||||
|
|
||||||
@ -87,9 +85,9 @@ use only first packet
|
|||||||
d3Jvbmc=
|
d3Jvbmc=
|
||||||
=vCYP
|
=vCYP
|
||||||
-----END PGP MESSAGE-----
|
-----END PGP MESSAGE-----
|
||||||
');
|
'), 'escape');
|
||||||
dearmor
|
encode
|
||||||
---------
|
--------
|
||||||
right
|
right
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
@ -287,7 +287,7 @@ FwsDabdQUz5O7bgNSnxfmyw1OifGF+W2bIn/8W+0rDf8u3+O+Q==
|
|||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- Checking various data
|
-- Checking various data
|
||||||
select encode(digest(pgp_sym_decrypt(dearmor('
|
select digest(pgp_sym_decrypt(dearmor('
|
||||||
-----BEGIN PGP MESSAGE-----
|
-----BEGIN PGP MESSAGE-----
|
||||||
Comment: dat1.aes.sha1.mdc.s2k3.z0
|
Comment: dat1.aes.sha1.mdc.s2k3.z0
|
||||||
|
|
||||||
@ -295,14 +295,13 @@ jA0EBwMCGJ+SpuOysINg0kQBJfSjzsW0x4OVcAyr17O7FBvMTwIGeGcJd99oTQU8
|
|||||||
Xtx3kDqnhUq9Z1fS3qPbi5iNP2A9NxOBxPWz2JzxhydANlgbxg==
|
Xtx3kDqnhUq9Z1fS3qPbi5iNP2A9NxOBxPWz2JzxhydANlgbxg==
|
||||||
=W/ik
|
=W/ik
|
||||||
-----END PGP MESSAGE-----
|
-----END PGP MESSAGE-----
|
||||||
'), '0123456789abcdefghij'), 'sha1'), 'hex');
|
'), '0123456789abcdefghij'), 'sha1');
|
||||||
encode
|
digest
|
||||||
------------------------------------------
|
--------------------------------------------
|
||||||
0225e3ede6f2587b076d021a189ff60aad67e066
|
\x0225e3ede6f2587b076d021a189ff60aad67e066
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- expected: 0225e3ede6f2587b076d021a189ff60aad67e066
|
select digest(pgp_sym_decrypt(dearmor('
|
||||||
select encode(digest(pgp_sym_decrypt(dearmor('
|
|
||||||
-----BEGIN PGP MESSAGE-----
|
-----BEGIN PGP MESSAGE-----
|
||||||
Comment: dat2.aes.sha1.mdc.s2k3.z0
|
Comment: dat2.aes.sha1.mdc.s2k3.z0
|
||||||
|
|
||||||
@ -310,14 +309,13 @@ jA0EBwMCvdpDvidNzMxg0jUBvj8eS2+1t/9/zgemxvhtc0fvdKGGbjH7dleaTJRB
|
|||||||
SaV9L04ky1qECNDx3XjnoKLC+H7IOQ==
|
SaV9L04ky1qECNDx3XjnoKLC+H7IOQ==
|
||||||
=Fxen
|
=Fxen
|
||||||
-----END PGP MESSAGE-----
|
-----END PGP MESSAGE-----
|
||||||
'), '0123456789abcdefghij'), 'sha1'), 'hex');
|
'), '0123456789abcdefghij'), 'sha1');
|
||||||
encode
|
digest
|
||||||
------------------------------------------
|
--------------------------------------------
|
||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
\xda39a3ee5e6b4b0d3255bfef95601890afd80709
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- expected: da39a3ee5e6b4b0d3255bfef95601890afd80709
|
select digest(pgp_sym_decrypt(dearmor('
|
||||||
select encode(digest(pgp_sym_decrypt(dearmor('
|
|
||||||
-----BEGIN PGP MESSAGE-----
|
-----BEGIN PGP MESSAGE-----
|
||||||
Comment: dat3.aes.sha1.mdc.s2k3.z0
|
Comment: dat3.aes.sha1.mdc.s2k3.z0
|
||||||
|
|
||||||
@ -326,15 +324,14 @@ gFnkUKIE0PSaYFp+Yi1VlRfUtRQ/X/LYNGa7tWZS+4VQajz2Xtz4vUeAEiYFYPXk
|
|||||||
73Hb8m1yRhQK
|
73Hb8m1yRhQK
|
||||||
=ivrD
|
=ivrD
|
||||||
-----END PGP MESSAGE-----
|
-----END PGP MESSAGE-----
|
||||||
'), '0123456789abcdefghij'), 'sha1'), 'hex');
|
'), '0123456789abcdefghij'), 'sha1');
|
||||||
encode
|
digest
|
||||||
------------------------------------------
|
--------------------------------------------
|
||||||
5e5c135efc0dd00633efc6dfd6e731ea408a5b4c
|
\x5e5c135efc0dd00633efc6dfd6e731ea408a5b4c
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- expected: 5e5c135efc0dd00633efc6dfd6e731ea408a5b4c
|
|
||||||
-- Checking CRLF
|
-- Checking CRLF
|
||||||
select encode(digest(pgp_sym_decrypt(dearmor('
|
select digest(pgp_sym_decrypt(dearmor('
|
||||||
-----BEGIN PGP MESSAGE-----
|
-----BEGIN PGP MESSAGE-----
|
||||||
Comment: crlf mess
|
Comment: crlf mess
|
||||||
|
|
||||||
@ -342,14 +339,13 @@ ww0ECQMCt7VAtby6l4Bi0lgB5KMIZiiF/b3CfMfUyY0eDncsGXtkbu1X+l9brjpMP8eJnY79Amms
|
|||||||
a3nsOzKTXUfS9VyaXo8IrncM6n7fdaXpwba/3tNsAhJG4lDv1k4g9v8Ix2dfv6Rs
|
a3nsOzKTXUfS9VyaXo8IrncM6n7fdaXpwba/3tNsAhJG4lDv1k4g9v8Ix2dfv6Rs
|
||||||
=mBP9
|
=mBP9
|
||||||
-----END PGP MESSAGE-----
|
-----END PGP MESSAGE-----
|
||||||
'), 'key', 'convert-crlf=0'), 'sha1'), 'hex');
|
'), 'key', 'convert-crlf=0'), 'sha1');
|
||||||
encode
|
digest
|
||||||
------------------------------------------
|
--------------------------------------------
|
||||||
9353062be7720f1446d30b9e75573a4833886784
|
\x9353062be7720f1446d30b9e75573a4833886784
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- expected: 9353062be7720f1446d30b9e75573a4833886784
|
select digest(pgp_sym_decrypt(dearmor('
|
||||||
select encode(digest(pgp_sym_decrypt(dearmor('
|
|
||||||
-----BEGIN PGP MESSAGE-----
|
-----BEGIN PGP MESSAGE-----
|
||||||
Comment: crlf mess
|
Comment: crlf mess
|
||||||
|
|
||||||
@ -357,13 +353,12 @@ ww0ECQMCt7VAtby6l4Bi0lgB5KMIZiiF/b3CfMfUyY0eDncsGXtkbu1X+l9brjpMP8eJnY79Amms
|
|||||||
a3nsOzKTXUfS9VyaXo8IrncM6n7fdaXpwba/3tNsAhJG4lDv1k4g9v8Ix2dfv6Rs
|
a3nsOzKTXUfS9VyaXo8IrncM6n7fdaXpwba/3tNsAhJG4lDv1k4g9v8Ix2dfv6Rs
|
||||||
=mBP9
|
=mBP9
|
||||||
-----END PGP MESSAGE-----
|
-----END PGP MESSAGE-----
|
||||||
'), 'key', 'convert-crlf=1'), 'sha1'), 'hex');
|
'), 'key', 'convert-crlf=1'), 'sha1');
|
||||||
encode
|
digest
|
||||||
------------------------------------------
|
--------------------------------------------
|
||||||
7efefcab38467f7484d6fa43dc86cf5281bd78e2
|
\x7efefcab38467f7484d6fa43dc86cf5281bd78e2
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- expected: 7efefcab38467f7484d6fa43dc86cf5281bd78e2
|
|
||||||
-- check BUG #11905, problem with messages 6 less than a power of 2.
|
-- check BUG #11905, problem with messages 6 less than a power of 2.
|
||||||
select pgp_sym_decrypt(pgp_sym_encrypt(repeat('x',65530),'1'),'1') = repeat('x',65530);
|
select pgp_sym_decrypt(pgp_sym_encrypt(repeat('x',65530),'1'),'1') = repeat('x',65530);
|
||||||
?column?
|
?column?
|
||||||
@ -371,7 +366,6 @@ select pgp_sym_decrypt(pgp_sym_encrypt(repeat('x',65530),'1'),'1') = repeat('x',
|
|||||||
t
|
t
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- expected: true
|
|
||||||
-- Negative tests
|
-- Negative tests
|
||||||
-- Decryption with a certain incorrect key yields an apparent Literal Data
|
-- Decryption with a certain incorrect key yields an apparent Literal Data
|
||||||
-- packet reporting its content to be binary data. Ciphertext source:
|
-- packet reporting its content to be binary data. Ciphertext source:
|
||||||
|
@ -283,7 +283,7 @@ FwsDabdQUz5O7bgNSnxfmyw1OifGF+W2bIn/8W+0rDf8u3+O+Q==
|
|||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- Checking various data
|
-- Checking various data
|
||||||
select encode(digest(pgp_sym_decrypt(dearmor('
|
select digest(pgp_sym_decrypt(dearmor('
|
||||||
-----BEGIN PGP MESSAGE-----
|
-----BEGIN PGP MESSAGE-----
|
||||||
Comment: dat1.aes.sha1.mdc.s2k3.z0
|
Comment: dat1.aes.sha1.mdc.s2k3.z0
|
||||||
|
|
||||||
@ -291,14 +291,13 @@ jA0EBwMCGJ+SpuOysINg0kQBJfSjzsW0x4OVcAyr17O7FBvMTwIGeGcJd99oTQU8
|
|||||||
Xtx3kDqnhUq9Z1fS3qPbi5iNP2A9NxOBxPWz2JzxhydANlgbxg==
|
Xtx3kDqnhUq9Z1fS3qPbi5iNP2A9NxOBxPWz2JzxhydANlgbxg==
|
||||||
=W/ik
|
=W/ik
|
||||||
-----END PGP MESSAGE-----
|
-----END PGP MESSAGE-----
|
||||||
'), '0123456789abcdefghij'), 'sha1'), 'hex');
|
'), '0123456789abcdefghij'), 'sha1');
|
||||||
encode
|
digest
|
||||||
------------------------------------------
|
--------------------------------------------
|
||||||
0225e3ede6f2587b076d021a189ff60aad67e066
|
\x0225e3ede6f2587b076d021a189ff60aad67e066
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- expected: 0225e3ede6f2587b076d021a189ff60aad67e066
|
select digest(pgp_sym_decrypt(dearmor('
|
||||||
select encode(digest(pgp_sym_decrypt(dearmor('
|
|
||||||
-----BEGIN PGP MESSAGE-----
|
-----BEGIN PGP MESSAGE-----
|
||||||
Comment: dat2.aes.sha1.mdc.s2k3.z0
|
Comment: dat2.aes.sha1.mdc.s2k3.z0
|
||||||
|
|
||||||
@ -306,14 +305,13 @@ jA0EBwMCvdpDvidNzMxg0jUBvj8eS2+1t/9/zgemxvhtc0fvdKGGbjH7dleaTJRB
|
|||||||
SaV9L04ky1qECNDx3XjnoKLC+H7IOQ==
|
SaV9L04ky1qECNDx3XjnoKLC+H7IOQ==
|
||||||
=Fxen
|
=Fxen
|
||||||
-----END PGP MESSAGE-----
|
-----END PGP MESSAGE-----
|
||||||
'), '0123456789abcdefghij'), 'sha1'), 'hex');
|
'), '0123456789abcdefghij'), 'sha1');
|
||||||
encode
|
digest
|
||||||
------------------------------------------
|
--------------------------------------------
|
||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
\xda39a3ee5e6b4b0d3255bfef95601890afd80709
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- expected: da39a3ee5e6b4b0d3255bfef95601890afd80709
|
select digest(pgp_sym_decrypt(dearmor('
|
||||||
select encode(digest(pgp_sym_decrypt(dearmor('
|
|
||||||
-----BEGIN PGP MESSAGE-----
|
-----BEGIN PGP MESSAGE-----
|
||||||
Comment: dat3.aes.sha1.mdc.s2k3.z0
|
Comment: dat3.aes.sha1.mdc.s2k3.z0
|
||||||
|
|
||||||
@ -322,15 +320,14 @@ gFnkUKIE0PSaYFp+Yi1VlRfUtRQ/X/LYNGa7tWZS+4VQajz2Xtz4vUeAEiYFYPXk
|
|||||||
73Hb8m1yRhQK
|
73Hb8m1yRhQK
|
||||||
=ivrD
|
=ivrD
|
||||||
-----END PGP MESSAGE-----
|
-----END PGP MESSAGE-----
|
||||||
'), '0123456789abcdefghij'), 'sha1'), 'hex');
|
'), '0123456789abcdefghij'), 'sha1');
|
||||||
encode
|
digest
|
||||||
------------------------------------------
|
--------------------------------------------
|
||||||
5e5c135efc0dd00633efc6dfd6e731ea408a5b4c
|
\x5e5c135efc0dd00633efc6dfd6e731ea408a5b4c
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- expected: 5e5c135efc0dd00633efc6dfd6e731ea408a5b4c
|
|
||||||
-- Checking CRLF
|
-- Checking CRLF
|
||||||
select encode(digest(pgp_sym_decrypt(dearmor('
|
select digest(pgp_sym_decrypt(dearmor('
|
||||||
-----BEGIN PGP MESSAGE-----
|
-----BEGIN PGP MESSAGE-----
|
||||||
Comment: crlf mess
|
Comment: crlf mess
|
||||||
|
|
||||||
@ -338,14 +335,13 @@ ww0ECQMCt7VAtby6l4Bi0lgB5KMIZiiF/b3CfMfUyY0eDncsGXtkbu1X+l9brjpMP8eJnY79Amms
|
|||||||
a3nsOzKTXUfS9VyaXo8IrncM6n7fdaXpwba/3tNsAhJG4lDv1k4g9v8Ix2dfv6Rs
|
a3nsOzKTXUfS9VyaXo8IrncM6n7fdaXpwba/3tNsAhJG4lDv1k4g9v8Ix2dfv6Rs
|
||||||
=mBP9
|
=mBP9
|
||||||
-----END PGP MESSAGE-----
|
-----END PGP MESSAGE-----
|
||||||
'), 'key', 'convert-crlf=0'), 'sha1'), 'hex');
|
'), 'key', 'convert-crlf=0'), 'sha1');
|
||||||
encode
|
digest
|
||||||
------------------------------------------
|
--------------------------------------------
|
||||||
9353062be7720f1446d30b9e75573a4833886784
|
\x9353062be7720f1446d30b9e75573a4833886784
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- expected: 9353062be7720f1446d30b9e75573a4833886784
|
select digest(pgp_sym_decrypt(dearmor('
|
||||||
select encode(digest(pgp_sym_decrypt(dearmor('
|
|
||||||
-----BEGIN PGP MESSAGE-----
|
-----BEGIN PGP MESSAGE-----
|
||||||
Comment: crlf mess
|
Comment: crlf mess
|
||||||
|
|
||||||
@ -353,13 +349,12 @@ ww0ECQMCt7VAtby6l4Bi0lgB5KMIZiiF/b3CfMfUyY0eDncsGXtkbu1X+l9brjpMP8eJnY79Amms
|
|||||||
a3nsOzKTXUfS9VyaXo8IrncM6n7fdaXpwba/3tNsAhJG4lDv1k4g9v8Ix2dfv6Rs
|
a3nsOzKTXUfS9VyaXo8IrncM6n7fdaXpwba/3tNsAhJG4lDv1k4g9v8Ix2dfv6Rs
|
||||||
=mBP9
|
=mBP9
|
||||||
-----END PGP MESSAGE-----
|
-----END PGP MESSAGE-----
|
||||||
'), 'key', 'convert-crlf=1'), 'sha1'), 'hex');
|
'), 'key', 'convert-crlf=1'), 'sha1');
|
||||||
encode
|
digest
|
||||||
------------------------------------------
|
--------------------------------------------
|
||||||
7efefcab38467f7484d6fa43dc86cf5281bd78e2
|
\x7efefcab38467f7484d6fa43dc86cf5281bd78e2
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- expected: 7efefcab38467f7484d6fa43dc86cf5281bd78e2
|
|
||||||
-- check BUG #11905, problem with messages 6 less than a power of 2.
|
-- check BUG #11905, problem with messages 6 less than a power of 2.
|
||||||
select pgp_sym_decrypt(pgp_sym_encrypt(repeat('x',65530),'1'),'1') = repeat('x',65530);
|
select pgp_sym_decrypt(pgp_sym_encrypt(repeat('x',65530),'1'),'1') = repeat('x',65530);
|
||||||
?column?
|
?column?
|
||||||
@ -367,7 +362,6 @@ select pgp_sym_decrypt(pgp_sym_encrypt(repeat('x',65530),'1'),'1') = repeat('x',
|
|||||||
t
|
t
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- expected: true
|
|
||||||
-- Negative tests
|
-- Negative tests
|
||||||
-- Decryption with a certain incorrect key yields an apparent Literal Data
|
-- Decryption with a certain incorrect key yields an apparent Literal Data
|
||||||
-- packet reporting its content to be binary data. Ciphertext source:
|
-- packet reporting its content to be binary data. Ciphertext source:
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
--
|
--
|
||||||
-- PGP encrypt
|
-- PGP encrypt
|
||||||
--
|
--
|
||||||
-- ensure consistent test output regardless of the default bytea format
|
|
||||||
SET bytea_output TO escape;
|
|
||||||
select pgp_sym_decrypt(pgp_sym_encrypt('Secret.', 'key'), 'key');
|
select pgp_sym_decrypt(pgp_sym_encrypt('Secret.', 'key'), 'key');
|
||||||
pgp_sym_decrypt
|
pgp_sym_decrypt
|
||||||
-----------------
|
-----------------
|
||||||
@ -47,9 +45,9 @@ NOTICE: pgp_decrypt: unexpected compress_algo: expected 1 got 0
|
|||||||
select pgp_sym_decrypt(pgp_sym_encrypt_bytea('Binary', 'baz'), 'baz');
|
select pgp_sym_decrypt(pgp_sym_encrypt_bytea('Binary', 'baz'), 'baz');
|
||||||
ERROR: Not text data
|
ERROR: Not text data
|
||||||
-- text as bytea
|
-- text as bytea
|
||||||
select pgp_sym_decrypt_bytea(pgp_sym_encrypt('Text', 'baz'), 'baz');
|
select encode(pgp_sym_decrypt_bytea(pgp_sym_encrypt('Text', 'baz'), 'baz'), 'escape');
|
||||||
pgp_sym_decrypt_bytea
|
encode
|
||||||
-----------------------
|
--------
|
||||||
Text
|
Text
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
@ -190,21 +188,21 @@ select pgp_sym_decrypt(
|
|||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- crlf
|
-- crlf
|
||||||
select encode(pgp_sym_decrypt_bytea(
|
select pgp_sym_decrypt_bytea(
|
||||||
pgp_sym_encrypt(E'1\n2\n3\r\n', 'key', 'convert-crlf=1'),
|
pgp_sym_encrypt(E'1\n2\n3\r\n', 'key', 'convert-crlf=1'),
|
||||||
'key'), 'hex');
|
'key');
|
||||||
encode
|
pgp_sym_decrypt_bytea
|
||||||
----------------------
|
------------------------
|
||||||
310d0a320d0a330d0d0a
|
\x310d0a320d0a330d0d0a
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- conversion should be lossless
|
-- conversion should be lossless
|
||||||
select encode(digest(pgp_sym_decrypt(
|
select digest(pgp_sym_decrypt(
|
||||||
pgp_sym_encrypt(E'\r\n0\n1\r\r\n\n2\r', 'key', 'convert-crlf=1'),
|
pgp_sym_encrypt(E'\r\n0\n1\r\r\n\n2\r', 'key', 'convert-crlf=1'),
|
||||||
'key', 'convert-crlf=1'), 'sha1'), 'hex') as result,
|
'key', 'convert-crlf=1'), 'sha1') as result,
|
||||||
encode(digest(E'\r\n0\n1\r\r\n\n2\r', 'sha1'), 'hex') as expect;
|
digest(E'\r\n0\n1\r\r\n\n2\r', 'sha1') as expect;
|
||||||
result | expect
|
result | expect
|
||||||
------------------------------------------+------------------------------------------
|
--------------------------------------------+--------------------------------------------
|
||||||
47bde5d88d6ef8770572b9cbb4278b402aa69966 | 47bde5d88d6ef8770572b9cbb4278b402aa69966
|
\x47bde5d88d6ef8770572b9cbb4278b402aa69966 | \x47bde5d88d6ef8770572b9cbb4278b402aa69966
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
--
|
--
|
||||||
-- PGP Public Key Encryption
|
-- PGP Public Key Encryption
|
||||||
--
|
--
|
||||||
-- ensure consistent test output regardless of the default bytea format
|
|
||||||
SET bytea_output TO escape;
|
|
||||||
-- successful encrypt/decrypt
|
-- successful encrypt/decrypt
|
||||||
select pgp_pub_decrypt(
|
select pgp_pub_decrypt(
|
||||||
pgp_pub_encrypt('Secret msg', dearmor(pubkey)),
|
pgp_pub_encrypt('Secret msg', dearmor(pubkey)),
|
||||||
@ -53,12 +51,12 @@ select pgp_pub_decrypt(
|
|||||||
from keytbl where keytbl.id=1;
|
from keytbl where keytbl.id=1;
|
||||||
ERROR: Refusing to encrypt with secret key
|
ERROR: Refusing to encrypt with secret key
|
||||||
-- does text-to-bytea works
|
-- does text-to-bytea works
|
||||||
select pgp_pub_decrypt_bytea(
|
select encode(pgp_pub_decrypt_bytea(
|
||||||
pgp_pub_encrypt('Secret msg', dearmor(pubkey)),
|
pgp_pub_encrypt('Secret msg', dearmor(pubkey)),
|
||||||
dearmor(seckey))
|
dearmor(seckey)), 'escape')
|
||||||
from keytbl where keytbl.id=1;
|
from keytbl where keytbl.id=1;
|
||||||
pgp_pub_decrypt_bytea
|
encode
|
||||||
-----------------------
|
------------
|
||||||
Secret msg
|
Secret msg
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
@ -1,125 +1,122 @@
|
|||||||
--
|
--
|
||||||
-- AES cipher (aka Rijndael-128, -192, or -256)
|
-- AES cipher (aka Rijndael-128, -192, or -256)
|
||||||
--
|
--
|
||||||
-- ensure consistent test output regardless of the default bytea format
|
|
||||||
SET bytea_output TO escape;
|
|
||||||
-- some standard Rijndael testvalues
|
-- some standard Rijndael testvalues
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt(
|
||||||
decode('00112233445566778899aabbccddeeff', 'hex'),
|
'\x00112233445566778899aabbccddeeff',
|
||||||
decode('000102030405060708090a0b0c0d0e0f', 'hex'),
|
'\x000102030405060708090a0b0c0d0e0f',
|
||||||
'aes-ecb/pad:none'), 'hex');
|
'aes-ecb/pad:none');
|
||||||
encode
|
encrypt
|
||||||
----------------------------------
|
------------------------------------
|
||||||
69c4e0d86a7b0430d8cdb78070b4c55a
|
\x69c4e0d86a7b0430d8cdb78070b4c55a
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt(
|
||||||
decode('00112233445566778899aabbccddeeff', 'hex'),
|
'\x00112233445566778899aabbccddeeff',
|
||||||
decode('000102030405060708090a0b0c0d0e0f1011121314151617', 'hex'),
|
'\x000102030405060708090a0b0c0d0e0f1011121314151617',
|
||||||
'aes-ecb/pad:none'), 'hex');
|
'aes-ecb/pad:none');
|
||||||
encode
|
encrypt
|
||||||
----------------------------------
|
------------------------------------
|
||||||
dda97ca4864cdfe06eaf70a0ec0d7191
|
\xdda97ca4864cdfe06eaf70a0ec0d7191
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt(
|
||||||
decode('00112233445566778899aabbccddeeff', 'hex'),
|
'\x00112233445566778899aabbccddeeff',
|
||||||
decode('000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f', 'hex'),
|
'\x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f',
|
||||||
'aes-ecb/pad:none'), 'hex');
|
'aes-ecb/pad:none');
|
||||||
encode
|
encrypt
|
||||||
----------------------------------
|
------------------------------------
|
||||||
8ea2b7ca516745bfeafc49904b496089
|
\x8ea2b7ca516745bfeafc49904b496089
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- cbc
|
-- cbc
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt(
|
||||||
decode('00112233445566778899aabbccddeeff', 'hex'),
|
'\x00112233445566778899aabbccddeeff',
|
||||||
decode('000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f', 'hex'),
|
'\x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f',
|
||||||
'aes-cbc/pad:none'), 'hex');
|
'aes-cbc/pad:none');
|
||||||
encode
|
encrypt
|
||||||
----------------------------------
|
------------------------------------
|
||||||
8ea2b7ca516745bfeafc49904b496089
|
\x8ea2b7ca516745bfeafc49904b496089
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- key padding
|
-- key padding
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt(
|
||||||
decode('0011223344', 'hex'),
|
'\x0011223344',
|
||||||
decode('000102030405', 'hex'),
|
'\x000102030405',
|
||||||
'aes-cbc'), 'hex');
|
'aes-cbc');
|
||||||
encode
|
encrypt
|
||||||
----------------------------------
|
------------------------------------
|
||||||
189a28932213f017b246678dbc28655f
|
\x189a28932213f017b246678dbc28655f
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt(
|
||||||
decode('0011223344', 'hex'),
|
'\x0011223344',
|
||||||
decode('000102030405060708090a0b0c0d0e0f10111213', 'hex'),
|
'\x000102030405060708090a0b0c0d0e0f10111213',
|
||||||
'aes-cbc'), 'hex');
|
'aes-cbc');
|
||||||
encode
|
encrypt
|
||||||
----------------------------------
|
------------------------------------
|
||||||
3b02279162d15580e069d3a71407a556
|
\x3b02279162d15580e069d3a71407a556
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt(
|
||||||
decode('0011223344', 'hex'),
|
'\x0011223344',
|
||||||
decode('000102030405060708090a0b0c0d0e0f101112131415161718191a1b', 'hex'),
|
'\x000102030405060708090a0b0c0d0e0f101112131415161718191a1b',
|
||||||
'aes-cbc'), 'hex');
|
'aes-cbc');
|
||||||
encode
|
encrypt
|
||||||
----------------------------------
|
------------------------------------
|
||||||
4facb6a041d53e0a5a73289170901fe7
|
\x4facb6a041d53e0a5a73289170901fe7
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- empty data
|
-- empty data
|
||||||
select encode(encrypt('', 'foo', 'aes'), 'hex');
|
select encrypt('', 'foo', 'aes');
|
||||||
encode
|
encrypt
|
||||||
----------------------------------
|
------------------------------------
|
||||||
b48cc3338a2eb293b6007ef72c360d48
|
\xb48cc3338a2eb293b6007ef72c360d48
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- 10 bytes key
|
-- 10 bytes key
|
||||||
select encode(encrypt('foo', '0123456789', 'aes'), 'hex');
|
select encrypt('foo', '0123456789', 'aes');
|
||||||
encode
|
encrypt
|
||||||
----------------------------------
|
------------------------------------
|
||||||
f397f03d2819b7172b68d0706fda4693
|
\xf397f03d2819b7172b68d0706fda4693
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- 22 bytes key
|
-- 22 bytes key
|
||||||
select encode(encrypt('foo', '0123456789012345678901', 'aes'), 'hex');
|
select encrypt('foo', '0123456789012345678901', 'aes');
|
||||||
encode
|
encrypt
|
||||||
----------------------------------
|
------------------------------------
|
||||||
5c9db77af02b4678117bcd8a71ae7f53
|
\x5c9db77af02b4678117bcd8a71ae7f53
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- decrypt
|
-- decrypt
|
||||||
select decrypt(encrypt('foo', '0123456', 'aes'), '0123456', 'aes');
|
select encode(decrypt(encrypt('foo', '0123456', 'aes'), '0123456', 'aes'), 'escape');
|
||||||
decrypt
|
encode
|
||||||
---------
|
--------
|
||||||
foo
|
foo
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- iv
|
-- iv
|
||||||
select encode(encrypt_iv('foo', '0123456', 'abcd', 'aes'), 'hex');
|
select encrypt_iv('foo', '0123456', 'abcd', 'aes');
|
||||||
encode
|
encrypt_iv
|
||||||
----------------------------------
|
------------------------------------
|
||||||
2c24cb7da91d6d5699801268b0f5adad
|
\x2c24cb7da91d6d5699801268b0f5adad
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
select decrypt_iv(decode('2c24cb7da91d6d5699801268b0f5adad', 'hex'),
|
select encode(decrypt_iv('\x2c24cb7da91d6d5699801268b0f5adad', '0123456', 'abcd', 'aes'), 'escape');
|
||||||
'0123456', 'abcd', 'aes');
|
encode
|
||||||
decrypt_iv
|
--------
|
||||||
------------
|
|
||||||
foo
|
foo
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- long message
|
-- long message
|
||||||
select encode(encrypt('Lets try a longer message.', '0123456789', 'aes'), 'hex');
|
select encrypt('Lets try a longer message.', '0123456789', 'aes');
|
||||||
encode
|
encrypt
|
||||||
------------------------------------------------------------------
|
--------------------------------------------------------------------
|
||||||
d9beb785dd5403ed02f66b755bb191b93ed93ca54930153f2c3b9ec7785056ad
|
\xd9beb785dd5403ed02f66b755bb191b93ed93ca54930153f2c3b9ec7785056ad
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
select decrypt(encrypt('Lets try a longer message.', '0123456789', 'aes'), '0123456789', 'aes');
|
select encode(decrypt(encrypt('Lets try a longer message.', '0123456789', 'aes'), '0123456789', 'aes'), 'escape');
|
||||||
decrypt
|
encode
|
||||||
----------------------------
|
----------------------------
|
||||||
Lets try a longer message.
|
Lets try a longer message.
|
||||||
(1 row)
|
(1 row)
|
||||||
|
@ -1,45 +1,45 @@
|
|||||||
--
|
--
|
||||||
-- SHA1 message digest
|
-- SHA1 message digest
|
||||||
--
|
--
|
||||||
SELECT encode(digest('', 'sha1'), 'hex');
|
SELECT digest('', 'sha1');
|
||||||
encode
|
digest
|
||||||
------------------------------------------
|
--------------------------------------------
|
||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
\xda39a3ee5e6b4b0d3255bfef95601890afd80709
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(digest('a', 'sha1'), 'hex');
|
SELECT digest('a', 'sha1');
|
||||||
encode
|
digest
|
||||||
------------------------------------------
|
--------------------------------------------
|
||||||
86f7e437faa5a7fce15d1ddcb9eaeaea377667b8
|
\x86f7e437faa5a7fce15d1ddcb9eaeaea377667b8
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(digest('abc', 'sha1'), 'hex');
|
SELECT digest('abc', 'sha1');
|
||||||
encode
|
digest
|
||||||
------------------------------------------
|
--------------------------------------------
|
||||||
a9993e364706816aba3e25717850c26c9cd0d89d
|
\xa9993e364706816aba3e25717850c26c9cd0d89d
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(digest('message digest', 'sha1'), 'hex');
|
SELECT digest('message digest', 'sha1');
|
||||||
encode
|
digest
|
||||||
------------------------------------------
|
--------------------------------------------
|
||||||
c12252ceda8be8994d5fa0290a47231c1d16aae3
|
\xc12252ceda8be8994d5fa0290a47231c1d16aae3
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(digest('abcdefghijklmnopqrstuvwxyz', 'sha1'), 'hex');
|
SELECT digest('abcdefghijklmnopqrstuvwxyz', 'sha1');
|
||||||
encode
|
digest
|
||||||
------------------------------------------
|
--------------------------------------------
|
||||||
32d10c7b8cf96570ca04ce37f2a19d84240d3a89
|
\x32d10c7b8cf96570ca04ce37f2a19d84240d3a89
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(digest('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', 'sha1'), 'hex');
|
SELECT digest('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', 'sha1');
|
||||||
encode
|
digest
|
||||||
------------------------------------------
|
--------------------------------------------
|
||||||
761c457bf73b14d27e9e9265c46f4b4dda11f940
|
\x761c457bf73b14d27e9e9265c46f4b4dda11f940
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(digest('12345678901234567890123456789012345678901234567890123456789012345678901234567890', 'sha1'), 'hex');
|
SELECT digest('12345678901234567890123456789012345678901234567890123456789012345678901234567890', 'sha1');
|
||||||
encode
|
digest
|
||||||
------------------------------------------
|
--------------------------------------------
|
||||||
50abf5706a150990a08b2c5ea40fa0e585554732
|
\x50abf5706a150990a08b2c5ea40fa0e585554732
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
@ -2,138 +2,138 @@
|
|||||||
-- SHA2 family
|
-- SHA2 family
|
||||||
--
|
--
|
||||||
-- SHA224
|
-- SHA224
|
||||||
SELECT encode(digest('', 'sha224'), 'hex');
|
SELECT digest('', 'sha224');
|
||||||
encode
|
digest
|
||||||
----------------------------------------------------------
|
------------------------------------------------------------
|
||||||
d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f
|
\xd14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(digest('a', 'sha224'), 'hex');
|
SELECT digest('a', 'sha224');
|
||||||
encode
|
digest
|
||||||
----------------------------------------------------------
|
------------------------------------------------------------
|
||||||
abd37534c7d9a2efb9465de931cd7055ffdb8879563ae98078d6d6d5
|
\xabd37534c7d9a2efb9465de931cd7055ffdb8879563ae98078d6d6d5
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(digest('abc', 'sha224'), 'hex');
|
SELECT digest('abc', 'sha224');
|
||||||
encode
|
digest
|
||||||
----------------------------------------------------------
|
------------------------------------------------------------
|
||||||
23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7
|
\x23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(digest('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq', 'sha224'), 'hex');
|
SELECT digest('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq', 'sha224');
|
||||||
encode
|
digest
|
||||||
----------------------------------------------------------
|
------------------------------------------------------------
|
||||||
75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525
|
\x75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(digest('12345678901234567890123456789012345678901234567890123456789012345678901234567890', 'sha224'), 'hex');
|
SELECT digest('12345678901234567890123456789012345678901234567890123456789012345678901234567890', 'sha224');
|
||||||
encode
|
digest
|
||||||
----------------------------------------------------------
|
------------------------------------------------------------
|
||||||
b50aecbe4e9bb0b57bc5f3ae760a8e01db24f203fb3cdcd13148046e
|
\xb50aecbe4e9bb0b57bc5f3ae760a8e01db24f203fb3cdcd13148046e
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- SHA256
|
-- SHA256
|
||||||
SELECT encode(digest('', 'sha256'), 'hex');
|
SELECT digest('', 'sha256');
|
||||||
encode
|
digest
|
||||||
------------------------------------------------------------------
|
--------------------------------------------------------------------
|
||||||
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
\xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(digest('a', 'sha256'), 'hex');
|
SELECT digest('a', 'sha256');
|
||||||
encode
|
digest
|
||||||
------------------------------------------------------------------
|
--------------------------------------------------------------------
|
||||||
ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb
|
\xca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(digest('abc', 'sha256'), 'hex');
|
SELECT digest('abc', 'sha256');
|
||||||
encode
|
digest
|
||||||
------------------------------------------------------------------
|
--------------------------------------------------------------------
|
||||||
ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
|
\xba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(digest('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq', 'sha256'), 'hex');
|
SELECT digest('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq', 'sha256');
|
||||||
encode
|
digest
|
||||||
------------------------------------------------------------------
|
--------------------------------------------------------------------
|
||||||
248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1
|
\x248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(digest('12345678901234567890123456789012345678901234567890123456789012345678901234567890', 'sha256'), 'hex');
|
SELECT digest('12345678901234567890123456789012345678901234567890123456789012345678901234567890', 'sha256');
|
||||||
encode
|
digest
|
||||||
------------------------------------------------------------------
|
--------------------------------------------------------------------
|
||||||
f371bc4a311f2b009eef952dd83ca80e2b60026c8e935592d0f9c308453c813e
|
\xf371bc4a311f2b009eef952dd83ca80e2b60026c8e935592d0f9c308453c813e
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- SHA384
|
-- SHA384
|
||||||
SELECT encode(digest('', 'sha384'), 'hex');
|
SELECT digest('', 'sha384');
|
||||||
encode
|
digest
|
||||||
--------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------
|
||||||
38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b
|
\x38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(digest('a', 'sha384'), 'hex');
|
SELECT digest('a', 'sha384');
|
||||||
encode
|
digest
|
||||||
--------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------
|
||||||
54a59b9f22b0b80880d8427e548b7c23abd873486e1f035dce9cd697e85175033caa88e6d57bc35efae0b5afd3145f31
|
\x54a59b9f22b0b80880d8427e548b7c23abd873486e1f035dce9cd697e85175033caa88e6d57bc35efae0b5afd3145f31
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(digest('abc', 'sha384'), 'hex');
|
SELECT digest('abc', 'sha384');
|
||||||
encode
|
digest
|
||||||
--------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------
|
||||||
cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7
|
\xcb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(digest('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq', 'sha384'), 'hex');
|
SELECT digest('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq', 'sha384');
|
||||||
encode
|
digest
|
||||||
--------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------
|
||||||
3391fdddfc8dc7393707a65b1b4709397cf8b1d162af05abfe8f450de5f36bc6b0455a8520bc4e6f5fe95b1fe3c8452b
|
\x3391fdddfc8dc7393707a65b1b4709397cf8b1d162af05abfe8f450de5f36bc6b0455a8520bc4e6f5fe95b1fe3c8452b
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(digest('abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu', 'sha384'), 'hex');
|
SELECT digest('abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu', 'sha384');
|
||||||
encode
|
digest
|
||||||
--------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------
|
||||||
09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712fcc7c71a557e2db966c3e9fa91746039
|
\x09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712fcc7c71a557e2db966c3e9fa91746039
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(digest('abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz', 'sha384'), 'hex');
|
SELECT digest('abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz', 'sha384');
|
||||||
encode
|
digest
|
||||||
--------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------
|
||||||
3d208973ab3508dbbd7e2c2862ba290ad3010e4978c198dc4d8fd014e582823a89e16f9b2a7bbc1ac938e2d199e8bea4
|
\x3d208973ab3508dbbd7e2c2862ba290ad3010e4978c198dc4d8fd014e582823a89e16f9b2a7bbc1ac938e2d199e8bea4
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- SHA512
|
-- SHA512
|
||||||
SELECT encode(digest('', 'sha512'), 'hex');
|
SELECT digest('', 'sha512');
|
||||||
encode
|
digest
|
||||||
----------------------------------------------------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------------------------------------------------
|
||||||
cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
|
\xcf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(digest('a', 'sha512'), 'hex');
|
SELECT digest('a', 'sha512');
|
||||||
encode
|
digest
|
||||||
----------------------------------------------------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------------------------------------------------
|
||||||
1f40fc92da241694750979ee6cf582f2d5d7d28e18335de05abc54d0560e0f5302860c652bf08d560252aa5e74210546f369fbbbce8c12cfc7957b2652fe9a75
|
\x1f40fc92da241694750979ee6cf582f2d5d7d28e18335de05abc54d0560e0f5302860c652bf08d560252aa5e74210546f369fbbbce8c12cfc7957b2652fe9a75
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(digest('abc', 'sha512'), 'hex');
|
SELECT digest('abc', 'sha512');
|
||||||
encode
|
digest
|
||||||
----------------------------------------------------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------------------------------------------------
|
||||||
ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f
|
\xddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(digest('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq', 'sha512'), 'hex');
|
SELECT digest('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq', 'sha512');
|
||||||
encode
|
digest
|
||||||
----------------------------------------------------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------------------------------------------------
|
||||||
204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c33596fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445
|
\x204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c33596fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(digest('abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu', 'sha512'), 'hex');
|
SELECT digest('abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu', 'sha512');
|
||||||
encode
|
digest
|
||||||
----------------------------------------------------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------------------------------------------------
|
||||||
8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909
|
\x8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT encode(digest('abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz', 'sha512'), 'hex');
|
SELECT digest('abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz', 'sha512');
|
||||||
encode
|
digest
|
||||||
----------------------------------------------------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------------------------------------------------
|
||||||
930d0cefcb30ff1133b6898121f1cf3d27578afcafe8677c5257cf069911f75d8f5831b56ebfda67b278e66dff8b84fe2b2870f742a580d8edb41987232850c9
|
\x930d0cefcb30ff1133b6898121f1cf3d27578afcafe8677c5257cf069911f75d8f5831b56ebfda67b278e66dff8b84fe2b2870f742a580d8edb41987232850c9
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
@ -1,31 +1,25 @@
|
|||||||
--
|
--
|
||||||
-- 3DES cipher
|
-- 3DES cipher
|
||||||
--
|
--
|
||||||
-- ensure consistent test output regardless of the default bytea format
|
|
||||||
SET bytea_output TO escape;
|
|
||||||
|
|
||||||
-- test vector from somewhere
|
-- test vector from somewhere
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x8000000000000000',
|
||||||
decode('80 00 00 00 00 00 00 00', 'hex'),
|
'\x010101010101010101010101010101010101010101010101',
|
||||||
decode('01 01 01 01 01 01 01 01
|
'3des-ecb/pad:none');
|
||||||
01 01 01 01 01 01 01 01
|
|
||||||
01 01 01 01 01 01 01 01', 'hex'),
|
|
||||||
'3des-ecb/pad:none'), 'hex');
|
|
||||||
-- val 95 F8 A5 E5 DD 31 D9 00
|
|
||||||
|
|
||||||
select encode( encrypt('', 'foo', '3des'), 'hex');
|
select encrypt('', 'foo', '3des');
|
||||||
-- 10 bytes key
|
-- 10 bytes key
|
||||||
select encode( encrypt('foo', '0123456789', '3des'), 'hex');
|
select encrypt('foo', '0123456789', '3des');
|
||||||
-- 22 bytes key
|
-- 22 bytes key
|
||||||
select encode( encrypt('foo', '0123456789012345678901', '3des'), 'hex');
|
select encrypt('foo', '0123456789012345678901', '3des');
|
||||||
|
|
||||||
-- decrypt
|
-- decrypt
|
||||||
select decrypt(encrypt('foo', '0123456', '3des'), '0123456', '3des');
|
select encode(decrypt(encrypt('foo', '0123456', '3des'), '0123456', '3des'), 'escape');
|
||||||
|
|
||||||
-- iv
|
-- iv
|
||||||
select encode(encrypt_iv('foo', '0123456', 'abcd', '3des'), 'hex');
|
select encrypt_iv('foo', '0123456', 'abcd', '3des');
|
||||||
select decrypt_iv(decode('50735067b073bb93', 'hex'), '0123456', 'abcd', '3des');
|
select encode(decrypt_iv('\x50735067b073bb93', '0123456', 'abcd', '3des'), 'escape');
|
||||||
|
|
||||||
-- long message
|
-- long message
|
||||||
select encode(encrypt('Lets try a longer message.', '0123456789012345678901', '3des'), 'hex');
|
select encrypt('Lets try a longer message.', '0123456789012345678901', '3des');
|
||||||
select decrypt(encrypt('Lets try a longer message.', '0123456789012345678901', '3des'), '0123456789012345678901', '3des');
|
select encode(decrypt(encrypt('Lets try a longer message.', '0123456789012345678901', '3des'), '0123456789012345678901', '3des'), 'escape');
|
||||||
|
@ -1,92 +1,53 @@
|
|||||||
--
|
--
|
||||||
-- Blowfish cipher
|
-- Blowfish cipher
|
||||||
--
|
--
|
||||||
-- ensure consistent test output regardless of the default bytea format
|
|
||||||
SET bytea_output TO escape;
|
|
||||||
|
|
||||||
-- some standard Blowfish testvalues
|
-- some standard Blowfish testvalues
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x0000000000000000', '\x0000000000000000', 'bf-ecb/pad:none');
|
||||||
decode('0000000000000000', 'hex'),
|
SELECT encrypt('\xffffffffffffffff', '\xffffffffffffffff', 'bf-ecb/pad:none');
|
||||||
decode('0000000000000000', 'hex'),
|
SELECT encrypt('\x1000000000000001', '\x3000000000000000', 'bf-ecb/pad:none');
|
||||||
'bf-ecb/pad:none'), 'hex');
|
SELECT encrypt('\x1111111111111111', '\x1111111111111111', 'bf-ecb/pad:none');
|
||||||
|
SELECT encrypt('\x0123456789abcdef', '\xfedcba9876543210', 'bf-ecb/pad:none');
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x01a1d6d039776742', '\xfedcba9876543210', 'bf-ecb/pad:none');
|
||||||
decode('ffffffffffffffff', 'hex'),
|
SELECT encrypt('\xffffffffffffffff', '\x0000000000000000', 'bf-ecb/pad:none');
|
||||||
decode('ffffffffffffffff', 'hex'),
|
|
||||||
'bf-ecb/pad:none'), 'hex');
|
|
||||||
|
|
||||||
SELECT encode(encrypt(
|
|
||||||
decode('1000000000000001', 'hex'),
|
|
||||||
decode('3000000000000000', 'hex'),
|
|
||||||
'bf-ecb/pad:none'), 'hex');
|
|
||||||
|
|
||||||
SELECT encode(encrypt(
|
|
||||||
decode('1111111111111111', 'hex'),
|
|
||||||
decode('1111111111111111', 'hex'),
|
|
||||||
'bf-ecb/pad:none'), 'hex');
|
|
||||||
|
|
||||||
SELECT encode(encrypt(
|
|
||||||
decode('0123456789abcdef', 'hex'),
|
|
||||||
decode('fedcba9876543210', 'hex'),
|
|
||||||
'bf-ecb/pad:none'), 'hex');
|
|
||||||
|
|
||||||
SELECT encode(encrypt(
|
|
||||||
decode('01a1d6d039776742', 'hex'),
|
|
||||||
decode('fedcba9876543210', 'hex'),
|
|
||||||
'bf-ecb/pad:none'), 'hex');
|
|
||||||
|
|
||||||
SELECT encode(encrypt(
|
|
||||||
decode('ffffffffffffffff', 'hex'),
|
|
||||||
decode('0000000000000000', 'hex'),
|
|
||||||
'bf-ecb/pad:none'), 'hex');
|
|
||||||
|
|
||||||
-- setkey
|
-- setkey
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\xfedcba9876543210', '\xf0e1d2c3b4a5968778695a4b3c2d1e0f', 'bf-ecb/pad:none');
|
||||||
decode('fedcba9876543210', 'hex'),
|
|
||||||
decode('f0e1d2c3b4a5968778695a4b3c2d1e0f', 'hex'),
|
|
||||||
'bf-ecb/pad:none'), 'hex');
|
|
||||||
|
|
||||||
-- with padding
|
-- with padding
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x01234567890123456789', '\x33443344334433443344334433443344', 'bf-ecb');
|
||||||
decode('01234567890123456789', 'hex'),
|
|
||||||
decode('33443344334433443344334433443344', 'hex'),
|
|
||||||
'bf-ecb'), 'hex');
|
|
||||||
|
|
||||||
-- cbc
|
-- cbc
|
||||||
|
|
||||||
-- 28 bytes key
|
-- 28 bytes key
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5',
|
||||||
decode('6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5', 'hex'),
|
'\x37363534333231204e6f77206973207468652074696d6520666f7220',
|
||||||
decode('37363534333231204e6f77206973207468652074696d6520666f7220', 'hex'),
|
'bf-cbc');
|
||||||
'bf-cbc'), 'hex');
|
|
||||||
|
|
||||||
-- 29 bytes key
|
-- 29 bytes key
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5ff92cc',
|
||||||
decode('6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5ff92cc', 'hex'),
|
'\x37363534333231204e6f77206973207468652074696d6520666f722000',
|
||||||
decode('37363534333231204e6f77206973207468652074696d6520666f722000', 'hex'),
|
'bf-cbc');
|
||||||
'bf-cbc'), 'hex');
|
|
||||||
|
|
||||||
-- blowfish-448
|
-- blowfish-448
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\xfedcba9876543210',
|
||||||
decode('fedcba9876543210', 'hex'),
|
'\xf0e1d2c3b4a5968778695a4b3c2d1e0f001122334455667704689104c2fd3b2f584023641aba61761f1f1f1f0e0e0e0effffffffffffffff',
|
||||||
decode('f0e1d2c3b4a5968778695a4b3c2d1e0f001122334455667704689104c2fd3b2f584023641aba61761f1f1f1f0e0e0e0effffffffffffffff', 'hex'),
|
'bf-ecb/pad:none');
|
||||||
'bf-ecb/pad:none'), 'hex');
|
|
||||||
-- result: c04504012e4e1f53
|
|
||||||
|
|
||||||
-- empty data
|
-- empty data
|
||||||
select encode(encrypt('', 'foo', 'bf'), 'hex');
|
select encrypt('', 'foo', 'bf');
|
||||||
-- 10 bytes key
|
-- 10 bytes key
|
||||||
select encode(encrypt('foo', '0123456789', 'bf'), 'hex');
|
select encrypt('foo', '0123456789', 'bf');
|
||||||
-- 22 bytes key
|
-- 22 bytes key
|
||||||
select encode(encrypt('foo', '0123456789012345678901', 'bf'), 'hex');
|
select encrypt('foo', '0123456789012345678901', 'bf');
|
||||||
|
|
||||||
-- decrypt
|
-- decrypt
|
||||||
select decrypt(encrypt('foo', '0123456', 'bf'), '0123456', 'bf');
|
select encode(decrypt(encrypt('foo', '0123456', 'bf'), '0123456', 'bf'), 'escape');
|
||||||
|
|
||||||
-- iv
|
-- iv
|
||||||
select encode(encrypt_iv('foo', '0123456', 'abcd', 'bf'), 'hex');
|
select encrypt_iv('foo', '0123456', 'abcd', 'bf');
|
||||||
select decrypt_iv(decode('95c7e89322525d59', 'hex'), '0123456', 'abcd', 'bf');
|
select encode(decrypt_iv('\x95c7e89322525d59', '0123456', 'abcd', 'bf'), 'escape');
|
||||||
|
|
||||||
-- long message
|
-- long message
|
||||||
select encode(encrypt('Lets try a longer message.', '0123456789', 'bf'), 'hex');
|
select encrypt('Lets try a longer message.', '0123456789', 'bf');
|
||||||
select decrypt(encrypt('Lets try a longer message.', '0123456789', 'bf'), '0123456789', 'bf');
|
select encode(decrypt(encrypt('Lets try a longer message.', '0123456789', 'bf'), '0123456789', 'bf'), 'escape');
|
||||||
|
@ -1,47 +1,32 @@
|
|||||||
--
|
--
|
||||||
-- Cast5 cipher
|
-- Cast5 cipher
|
||||||
--
|
--
|
||||||
-- ensure consistent test output regardless of the default bytea format
|
|
||||||
SET bytea_output TO escape;
|
|
||||||
|
|
||||||
-- test vectors from RFC2144
|
-- test vectors from RFC2144
|
||||||
|
|
||||||
-- 128 bit key
|
-- 128 bit key
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x0123456789ABCDEF', '\x0123456712345678234567893456789A', 'cast5-ecb/pad:none');
|
||||||
decode('01 23 45 67 89 AB CD EF', 'hex'),
|
|
||||||
decode('01 23 45 67 12 34 56 78 23 45 67 89 34 56 78 9A', 'hex'),
|
|
||||||
'cast5-ecb/pad:none'), 'hex');
|
|
||||||
-- result: 23 8B 4F E5 84 7E 44 B2
|
|
||||||
|
|
||||||
-- 80 bit key
|
-- 80 bit key
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x0123456789ABCDEF', '\x01234567123456782345', 'cast5-ecb/pad:none');
|
||||||
decode('01 23 45 67 89 AB CD EF', 'hex'),
|
|
||||||
decode('01 23 45 67 12 34 56 78 23 45', 'hex'),
|
|
||||||
'cast5-ecb/pad:none'), 'hex');
|
|
||||||
-- result: EB 6A 71 1A 2C 02 27 1B
|
|
||||||
|
|
||||||
-- 40 bit key
|
-- 40 bit key
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x0123456789ABCDEF', '\x0123456712', 'cast5-ecb/pad:none');
|
||||||
decode('01 23 45 67 89 AB CD EF', 'hex'),
|
|
||||||
decode('01 23 45 67 12', 'hex'),
|
|
||||||
'cast5-ecb/pad:none'), 'hex');
|
|
||||||
-- result: 7A C8 16 D1 6E 9B 30 2E
|
|
||||||
|
|
||||||
-- cbc
|
-- cbc
|
||||||
|
|
||||||
-- empty data
|
-- empty data
|
||||||
select encode( encrypt('', 'foo', 'cast5'), 'hex');
|
select encrypt('', 'foo', 'cast5');
|
||||||
-- 10 bytes key
|
-- 10 bytes key
|
||||||
select encode( encrypt('foo', '0123456789', 'cast5'), 'hex');
|
select encrypt('foo', '0123456789', 'cast5');
|
||||||
|
|
||||||
-- decrypt
|
-- decrypt
|
||||||
select decrypt(encrypt('foo', '0123456', 'cast5'), '0123456', 'cast5');
|
select encode(decrypt(encrypt('foo', '0123456', 'cast5'), '0123456', 'cast5'), 'escape');
|
||||||
|
|
||||||
-- iv
|
-- iv
|
||||||
select encode(encrypt_iv('foo', '0123456', 'abcd', 'cast5'), 'hex');
|
select encrypt_iv('foo', '0123456', 'abcd', 'cast5');
|
||||||
select decrypt_iv(decode('384a970695ce016a', 'hex'),
|
select encode(decrypt_iv('\x384a970695ce016a', '0123456', 'abcd', 'cast5'), 'escape');
|
||||||
'0123456', 'abcd', 'cast5');
|
|
||||||
|
|
||||||
-- long message
|
-- long message
|
||||||
select encode(encrypt('Lets try a longer message.', '0123456789', 'cast5'), 'hex');
|
select encrypt('Lets try a longer message.', '0123456789', 'cast5');
|
||||||
select decrypt(encrypt('Lets try a longer message.', '0123456789', 'cast5'), '0123456789', 'cast5');
|
select encode(decrypt(encrypt('Lets try a longer message.', '0123456789', 'cast5'), '0123456789', 'cast5'), 'escape');
|
||||||
|
@ -1,29 +1,24 @@
|
|||||||
--
|
--
|
||||||
-- DES cipher
|
-- DES cipher
|
||||||
--
|
--
|
||||||
-- ensure consistent test output regardless of the default bytea format
|
|
||||||
SET bytea_output TO escape;
|
|
||||||
|
|
||||||
-- no official test vectors atm
|
-- no official test vectors atm
|
||||||
|
|
||||||
-- from blowfish.sql
|
-- from blowfish.sql
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt('\x0123456789abcdef', '\xfedcba9876543210', 'des-ecb/pad:none');
|
||||||
decode('0123456789abcdef', 'hex'),
|
|
||||||
decode('fedcba9876543210', 'hex'),
|
|
||||||
'des-ecb/pad:none'), 'hex');
|
|
||||||
|
|
||||||
-- empty data
|
-- empty data
|
||||||
select encode( encrypt('', 'foo', 'des'), 'hex');
|
select encrypt('', 'foo', 'des');
|
||||||
-- 8 bytes key
|
-- 8 bytes key
|
||||||
select encode( encrypt('foo', '01234589', 'des'), 'hex');
|
select encrypt('foo', '01234589', 'des');
|
||||||
|
|
||||||
-- decrypt
|
-- decrypt
|
||||||
select decrypt(encrypt('foo', '0123456', 'des'), '0123456', 'des');
|
select encode(decrypt(encrypt('foo', '0123456', 'des'), '0123456', 'des'), 'escape');
|
||||||
|
|
||||||
-- iv
|
-- iv
|
||||||
select encode(encrypt_iv('foo', '0123456', 'abcd', 'des'), 'hex');
|
select encrypt_iv('foo', '0123456', 'abcd', 'des');
|
||||||
select decrypt_iv(decode('50735067b073bb93', 'hex'), '0123456', 'abcd', 'des');
|
select encode(decrypt_iv('\x50735067b073bb93', '0123456', 'abcd', 'des'), 'escape');
|
||||||
|
|
||||||
-- long message
|
-- long message
|
||||||
select encode(encrypt('Lets try a longer message.', '01234567', 'des'), 'hex');
|
select encrypt('Lets try a longer message.', '01234567', 'des');
|
||||||
select decrypt(encrypt('Lets try a longer message.', '01234567', 'des'), '01234567', 'des');
|
select encode(decrypt(encrypt('Lets try a longer message.', '01234567', 'des'), '01234567', 'des'), 'escape');
|
||||||
|
@ -2,43 +2,43 @@
|
|||||||
-- HMAC-MD5
|
-- HMAC-MD5
|
||||||
--
|
--
|
||||||
|
|
||||||
SELECT encode(hmac(
|
SELECT hmac(
|
||||||
'Hi There',
|
'Hi There',
|
||||||
decode('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b', 'hex'),
|
'\x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b'::bytea,
|
||||||
'md5'), 'hex');
|
'md5');
|
||||||
|
|
||||||
-- 2
|
-- 2
|
||||||
SELECT encode(hmac(
|
SELECT hmac(
|
||||||
'Jefe',
|
'Jefe',
|
||||||
'what do ya want for nothing?',
|
'what do ya want for nothing?',
|
||||||
'md5'), 'hex');
|
'md5');
|
||||||
|
|
||||||
-- 3
|
-- 3
|
||||||
SELECT encode(hmac(
|
SELECT hmac(
|
||||||
decode('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd', 'hex'),
|
'\xdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd'::bytea,
|
||||||
decode('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'hex'),
|
'\xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'::bytea,
|
||||||
'md5'), 'hex');
|
'md5');
|
||||||
|
|
||||||
-- 4
|
-- 4
|
||||||
SELECT encode(hmac(
|
SELECT hmac(
|
||||||
decode('cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd', 'hex'),
|
'\xcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd'::bytea,
|
||||||
decode('0102030405060708090a0b0c0d0e0f10111213141516171819', 'hex'),
|
'\x0102030405060708090a0b0c0d0e0f10111213141516171819'::bytea,
|
||||||
'md5'), 'hex');
|
'md5');
|
||||||
|
|
||||||
-- 5
|
-- 5
|
||||||
SELECT encode(hmac(
|
SELECT hmac(
|
||||||
'Test With Truncation',
|
'Test With Truncation',
|
||||||
decode('0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c', 'hex'),
|
'\x0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c'::bytea,
|
||||||
'md5'), 'hex');
|
'md5');
|
||||||
|
|
||||||
-- 6
|
-- 6
|
||||||
SELECT encode(hmac(
|
SELECT hmac(
|
||||||
'Test Using Larger Than Block-Size Key - Hash Key First',
|
'Test Using Larger Than Block-Size Key - Hash Key First',
|
||||||
decode('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'hex'),
|
'\xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'::bytea,
|
||||||
'md5'), 'hex');
|
'md5');
|
||||||
|
|
||||||
-- 7
|
-- 7
|
||||||
SELECT encode(hmac(
|
SELECT hmac(
|
||||||
'Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data',
|
'Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data',
|
||||||
decode('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'hex'),
|
'\xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'::bytea,
|
||||||
'md5'), 'hex');
|
'md5');
|
||||||
|
@ -2,43 +2,43 @@
|
|||||||
-- HMAC-SHA1
|
-- HMAC-SHA1
|
||||||
--
|
--
|
||||||
|
|
||||||
SELECT encode(hmac(
|
SELECT hmac(
|
||||||
'Hi There',
|
'Hi There',
|
||||||
decode('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b', 'hex'),
|
'\x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b'::bytea,
|
||||||
'sha1'), 'hex');
|
'sha1');
|
||||||
|
|
||||||
-- 2
|
-- 2
|
||||||
SELECT encode(hmac(
|
SELECT hmac(
|
||||||
'Jefe',
|
'Jefe',
|
||||||
'what do ya want for nothing?',
|
'what do ya want for nothing?',
|
||||||
'sha1'), 'hex');
|
'sha1');
|
||||||
|
|
||||||
-- 3
|
-- 3
|
||||||
SELECT encode(hmac(
|
SELECT hmac(
|
||||||
decode('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd', 'hex'),
|
'\xdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd'::bytea,
|
||||||
decode('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'hex'),
|
'\xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'::bytea,
|
||||||
'sha1'), 'hex');
|
'sha1');
|
||||||
|
|
||||||
-- 4
|
-- 4
|
||||||
SELECT encode(hmac(
|
SELECT hmac(
|
||||||
decode('cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd', 'hex'),
|
'\xcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd'::bytea,
|
||||||
decode('0102030405060708090a0b0c0d0e0f10111213141516171819', 'hex'),
|
'\x0102030405060708090a0b0c0d0e0f10111213141516171819'::bytea,
|
||||||
'sha1'), 'hex');
|
'sha1');
|
||||||
|
|
||||||
-- 5
|
-- 5
|
||||||
SELECT encode(hmac(
|
SELECT hmac(
|
||||||
'Test With Truncation',
|
'Test With Truncation',
|
||||||
decode('0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c', 'hex'),
|
'\x0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c'::bytea,
|
||||||
'sha1'), 'hex');
|
'sha1');
|
||||||
|
|
||||||
-- 6
|
-- 6
|
||||||
SELECT encode(hmac(
|
SELECT hmac(
|
||||||
'Test Using Larger Than Block-Size Key - Hash Key First',
|
'Test Using Larger Than Block-Size Key - Hash Key First',
|
||||||
decode('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'hex'),
|
'\xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'::bytea,
|
||||||
'sha1'), 'hex');
|
'sha1');
|
||||||
|
|
||||||
-- 7
|
-- 7
|
||||||
SELECT encode(hmac(
|
SELECT hmac(
|
||||||
'Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data',
|
'Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data',
|
||||||
decode('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'hex'),
|
'\xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'::bytea,
|
||||||
'sha1'), 'hex');
|
'sha1');
|
||||||
|
@ -4,13 +4,6 @@
|
|||||||
|
|
||||||
CREATE EXTENSION pgcrypto;
|
CREATE EXTENSION pgcrypto;
|
||||||
|
|
||||||
-- ensure consistent test output regardless of the default bytea format
|
|
||||||
SET bytea_output TO escape;
|
|
||||||
|
|
||||||
-- check for encoding fn's
|
|
||||||
SELECT encode('foo', 'hex');
|
|
||||||
SELECT decode('666f6f', 'hex');
|
|
||||||
|
|
||||||
-- check error handling
|
-- check error handling
|
||||||
select gen_salt('foo');
|
select gen_salt('foo');
|
||||||
select digest('foo', 'foo');
|
select digest('foo', 'foo');
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
-- MD5 message digest
|
-- MD5 message digest
|
||||||
--
|
--
|
||||||
|
|
||||||
SELECT encode(digest('', 'md5'), 'hex');
|
SELECT digest('', 'md5');
|
||||||
SELECT encode(digest('a', 'md5'), 'hex');
|
SELECT digest('a', 'md5');
|
||||||
SELECT encode(digest('abc', 'md5'), 'hex');
|
SELECT digest('abc', 'md5');
|
||||||
SELECT encode(digest('message digest', 'md5'), 'hex');
|
SELECT digest('message digest', 'md5');
|
||||||
SELECT encode(digest('abcdefghijklmnopqrstuvwxyz', 'md5'), 'hex');
|
SELECT digest('abcdefghijklmnopqrstuvwxyz', 'md5');
|
||||||
SELECT encode(digest('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', 'md5'), 'hex');
|
SELECT digest('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', 'md5');
|
||||||
SELECT encode(digest('12345678901234567890123456789012345678901234567890123456789012345678901234567890', 'md5'), 'hex');
|
SELECT digest('12345678901234567890123456789012345678901234567890123456789012345678901234567890', 'md5');
|
||||||
|
@ -1,19 +1,17 @@
|
|||||||
--
|
--
|
||||||
-- PGP Armor
|
-- PGP Armor
|
||||||
--
|
--
|
||||||
-- ensure consistent test output regardless of the default bytea format
|
|
||||||
SET bytea_output TO escape;
|
|
||||||
|
|
||||||
select armor('');
|
select armor('');
|
||||||
select armor('test');
|
select armor('test');
|
||||||
select dearmor(armor(''));
|
select encode(dearmor(armor('')), 'escape');
|
||||||
select dearmor(armor('zooka'));
|
select encode(dearmor(armor('zooka')), 'escape');
|
||||||
|
|
||||||
select armor('0123456789abcdef0123456789abcdef0123456789abcdef
|
select armor('0123456789abcdef0123456789abcdef0123456789abcdef
|
||||||
0123456789abcdef0123456789abcdef0123456789abcdef');
|
0123456789abcdef0123456789abcdef0123456789abcdef');
|
||||||
|
|
||||||
-- lots formatting
|
-- lots formatting
|
||||||
select dearmor(' a pgp msg:
|
select encode(dearmor(' a pgp msg:
|
||||||
|
|
||||||
-----BEGIN PGP MESSAGE-----
|
-----BEGIN PGP MESSAGE-----
|
||||||
Comment: Some junk
|
Comment: Some junk
|
||||||
@ -22,10 +20,10 @@ em9va2E=
|
|||||||
|
|
||||||
=D5cR
|
=D5cR
|
||||||
|
|
||||||
-----END PGP MESSAGE-----');
|
-----END PGP MESSAGE-----'), 'escape');
|
||||||
|
|
||||||
-- lots messages
|
-- lots messages
|
||||||
select dearmor('
|
select encode(dearmor('
|
||||||
wrong packet:
|
wrong packet:
|
||||||
-----BEGIN PGP MESSAGE-----
|
-----BEGIN PGP MESSAGE-----
|
||||||
|
|
||||||
@ -46,7 +44,7 @@ use only first packet
|
|||||||
d3Jvbmc=
|
d3Jvbmc=
|
||||||
=vCYP
|
=vCYP
|
||||||
-----END PGP MESSAGE-----
|
-----END PGP MESSAGE-----
|
||||||
');
|
'), 'escape');
|
||||||
|
|
||||||
-- bad crc
|
-- bad crc
|
||||||
select dearmor('
|
select dearmor('
|
||||||
|
@ -208,7 +208,7 @@ FwsDabdQUz5O7bgNSnxfmyw1OifGF+W2bIn/8W+0rDf8u3+O+Q==
|
|||||||
'), 'x');
|
'), 'x');
|
||||||
|
|
||||||
-- Checking various data
|
-- Checking various data
|
||||||
select encode(digest(pgp_sym_decrypt(dearmor('
|
select digest(pgp_sym_decrypt(dearmor('
|
||||||
-----BEGIN PGP MESSAGE-----
|
-----BEGIN PGP MESSAGE-----
|
||||||
Comment: dat1.aes.sha1.mdc.s2k3.z0
|
Comment: dat1.aes.sha1.mdc.s2k3.z0
|
||||||
|
|
||||||
@ -216,10 +216,9 @@ jA0EBwMCGJ+SpuOysINg0kQBJfSjzsW0x4OVcAyr17O7FBvMTwIGeGcJd99oTQU8
|
|||||||
Xtx3kDqnhUq9Z1fS3qPbi5iNP2A9NxOBxPWz2JzxhydANlgbxg==
|
Xtx3kDqnhUq9Z1fS3qPbi5iNP2A9NxOBxPWz2JzxhydANlgbxg==
|
||||||
=W/ik
|
=W/ik
|
||||||
-----END PGP MESSAGE-----
|
-----END PGP MESSAGE-----
|
||||||
'), '0123456789abcdefghij'), 'sha1'), 'hex');
|
'), '0123456789abcdefghij'), 'sha1');
|
||||||
-- expected: 0225e3ede6f2587b076d021a189ff60aad67e066
|
|
||||||
|
|
||||||
select encode(digest(pgp_sym_decrypt(dearmor('
|
select digest(pgp_sym_decrypt(dearmor('
|
||||||
-----BEGIN PGP MESSAGE-----
|
-----BEGIN PGP MESSAGE-----
|
||||||
Comment: dat2.aes.sha1.mdc.s2k3.z0
|
Comment: dat2.aes.sha1.mdc.s2k3.z0
|
||||||
|
|
||||||
@ -227,10 +226,9 @@ jA0EBwMCvdpDvidNzMxg0jUBvj8eS2+1t/9/zgemxvhtc0fvdKGGbjH7dleaTJRB
|
|||||||
SaV9L04ky1qECNDx3XjnoKLC+H7IOQ==
|
SaV9L04ky1qECNDx3XjnoKLC+H7IOQ==
|
||||||
=Fxen
|
=Fxen
|
||||||
-----END PGP MESSAGE-----
|
-----END PGP MESSAGE-----
|
||||||
'), '0123456789abcdefghij'), 'sha1'), 'hex');
|
'), '0123456789abcdefghij'), 'sha1');
|
||||||
-- expected: da39a3ee5e6b4b0d3255bfef95601890afd80709
|
|
||||||
|
|
||||||
select encode(digest(pgp_sym_decrypt(dearmor('
|
select digest(pgp_sym_decrypt(dearmor('
|
||||||
-----BEGIN PGP MESSAGE-----
|
-----BEGIN PGP MESSAGE-----
|
||||||
Comment: dat3.aes.sha1.mdc.s2k3.z0
|
Comment: dat3.aes.sha1.mdc.s2k3.z0
|
||||||
|
|
||||||
@ -239,11 +237,10 @@ gFnkUKIE0PSaYFp+Yi1VlRfUtRQ/X/LYNGa7tWZS+4VQajz2Xtz4vUeAEiYFYPXk
|
|||||||
73Hb8m1yRhQK
|
73Hb8m1yRhQK
|
||||||
=ivrD
|
=ivrD
|
||||||
-----END PGP MESSAGE-----
|
-----END PGP MESSAGE-----
|
||||||
'), '0123456789abcdefghij'), 'sha1'), 'hex');
|
'), '0123456789abcdefghij'), 'sha1');
|
||||||
-- expected: 5e5c135efc0dd00633efc6dfd6e731ea408a5b4c
|
|
||||||
|
|
||||||
-- Checking CRLF
|
-- Checking CRLF
|
||||||
select encode(digest(pgp_sym_decrypt(dearmor('
|
select digest(pgp_sym_decrypt(dearmor('
|
||||||
-----BEGIN PGP MESSAGE-----
|
-----BEGIN PGP MESSAGE-----
|
||||||
Comment: crlf mess
|
Comment: crlf mess
|
||||||
|
|
||||||
@ -251,10 +248,9 @@ ww0ECQMCt7VAtby6l4Bi0lgB5KMIZiiF/b3CfMfUyY0eDncsGXtkbu1X+l9brjpMP8eJnY79Amms
|
|||||||
a3nsOzKTXUfS9VyaXo8IrncM6n7fdaXpwba/3tNsAhJG4lDv1k4g9v8Ix2dfv6Rs
|
a3nsOzKTXUfS9VyaXo8IrncM6n7fdaXpwba/3tNsAhJG4lDv1k4g9v8Ix2dfv6Rs
|
||||||
=mBP9
|
=mBP9
|
||||||
-----END PGP MESSAGE-----
|
-----END PGP MESSAGE-----
|
||||||
'), 'key', 'convert-crlf=0'), 'sha1'), 'hex');
|
'), 'key', 'convert-crlf=0'), 'sha1');
|
||||||
-- expected: 9353062be7720f1446d30b9e75573a4833886784
|
|
||||||
|
|
||||||
select encode(digest(pgp_sym_decrypt(dearmor('
|
select digest(pgp_sym_decrypt(dearmor('
|
||||||
-----BEGIN PGP MESSAGE-----
|
-----BEGIN PGP MESSAGE-----
|
||||||
Comment: crlf mess
|
Comment: crlf mess
|
||||||
|
|
||||||
@ -262,12 +258,10 @@ ww0ECQMCt7VAtby6l4Bi0lgB5KMIZiiF/b3CfMfUyY0eDncsGXtkbu1X+l9brjpMP8eJnY79Amms
|
|||||||
a3nsOzKTXUfS9VyaXo8IrncM6n7fdaXpwba/3tNsAhJG4lDv1k4g9v8Ix2dfv6Rs
|
a3nsOzKTXUfS9VyaXo8IrncM6n7fdaXpwba/3tNsAhJG4lDv1k4g9v8Ix2dfv6Rs
|
||||||
=mBP9
|
=mBP9
|
||||||
-----END PGP MESSAGE-----
|
-----END PGP MESSAGE-----
|
||||||
'), 'key', 'convert-crlf=1'), 'sha1'), 'hex');
|
'), 'key', 'convert-crlf=1'), 'sha1');
|
||||||
-- expected: 7efefcab38467f7484d6fa43dc86cf5281bd78e2
|
|
||||||
|
|
||||||
-- check BUG #11905, problem with messages 6 less than a power of 2.
|
-- check BUG #11905, problem with messages 6 less than a power of 2.
|
||||||
select pgp_sym_decrypt(pgp_sym_encrypt(repeat('x',65530),'1'),'1') = repeat('x',65530);
|
select pgp_sym_decrypt(pgp_sym_encrypt(repeat('x',65530),'1'),'1') = repeat('x',65530);
|
||||||
-- expected: true
|
|
||||||
|
|
||||||
|
|
||||||
-- Negative tests
|
-- Negative tests
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
--
|
--
|
||||||
-- PGP encrypt
|
-- PGP encrypt
|
||||||
--
|
--
|
||||||
-- ensure consistent test output regardless of the default bytea format
|
|
||||||
SET bytea_output TO escape;
|
|
||||||
|
|
||||||
select pgp_sym_decrypt(pgp_sym_encrypt('Secret.', 'key'), 'key');
|
select pgp_sym_decrypt(pgp_sym_encrypt('Secret.', 'key'), 'key');
|
||||||
|
|
||||||
@ -30,7 +28,7 @@ select pgp_sym_decrypt(pgp_sym_encrypt('Secret.', 'key'),
|
|||||||
select pgp_sym_decrypt(pgp_sym_encrypt_bytea('Binary', 'baz'), 'baz');
|
select pgp_sym_decrypt(pgp_sym_encrypt_bytea('Binary', 'baz'), 'baz');
|
||||||
|
|
||||||
-- text as bytea
|
-- text as bytea
|
||||||
select pgp_sym_decrypt_bytea(pgp_sym_encrypt('Text', 'baz'), 'baz');
|
select encode(pgp_sym_decrypt_bytea(pgp_sym_encrypt('Text', 'baz'), 'baz'), 'escape');
|
||||||
|
|
||||||
|
|
||||||
-- algorithm change
|
-- algorithm change
|
||||||
@ -95,12 +93,12 @@ select pgp_sym_decrypt(
|
|||||||
'key', 'expect-disable-mdc=1');
|
'key', 'expect-disable-mdc=1');
|
||||||
|
|
||||||
-- crlf
|
-- crlf
|
||||||
select encode(pgp_sym_decrypt_bytea(
|
select pgp_sym_decrypt_bytea(
|
||||||
pgp_sym_encrypt(E'1\n2\n3\r\n', 'key', 'convert-crlf=1'),
|
pgp_sym_encrypt(E'1\n2\n3\r\n', 'key', 'convert-crlf=1'),
|
||||||
'key'), 'hex');
|
'key');
|
||||||
|
|
||||||
-- conversion should be lossless
|
-- conversion should be lossless
|
||||||
select encode(digest(pgp_sym_decrypt(
|
select digest(pgp_sym_decrypt(
|
||||||
pgp_sym_encrypt(E'\r\n0\n1\r\r\n\n2\r', 'key', 'convert-crlf=1'),
|
pgp_sym_encrypt(E'\r\n0\n1\r\r\n\n2\r', 'key', 'convert-crlf=1'),
|
||||||
'key', 'convert-crlf=1'), 'sha1'), 'hex') as result,
|
'key', 'convert-crlf=1'), 'sha1') as result,
|
||||||
encode(digest(E'\r\n0\n1\r\r\n\n2\r', 'sha1'), 'hex') as expect;
|
digest(E'\r\n0\n1\r\r\n\n2\r', 'sha1') as expect;
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
--
|
--
|
||||||
-- PGP Public Key Encryption
|
-- PGP Public Key Encryption
|
||||||
--
|
--
|
||||||
-- ensure consistent test output regardless of the default bytea format
|
|
||||||
SET bytea_output TO escape;
|
|
||||||
|
|
||||||
-- successful encrypt/decrypt
|
-- successful encrypt/decrypt
|
||||||
select pgp_pub_decrypt(
|
select pgp_pub_decrypt(
|
||||||
@ -38,9 +36,9 @@ select pgp_pub_decrypt(
|
|||||||
from keytbl where keytbl.id=1;
|
from keytbl where keytbl.id=1;
|
||||||
|
|
||||||
-- does text-to-bytea works
|
-- does text-to-bytea works
|
||||||
select pgp_pub_decrypt_bytea(
|
select encode(pgp_pub_decrypt_bytea(
|
||||||
pgp_pub_encrypt('Secret msg', dearmor(pubkey)),
|
pgp_pub_encrypt('Secret msg', dearmor(pubkey)),
|
||||||
dearmor(seckey))
|
dearmor(seckey)), 'escape')
|
||||||
from keytbl where keytbl.id=1;
|
from keytbl where keytbl.id=1;
|
||||||
|
|
||||||
-- and bytea-to-text?
|
-- and bytea-to-text?
|
||||||
|
@ -1,63 +1,60 @@
|
|||||||
--
|
--
|
||||||
-- AES cipher (aka Rijndael-128, -192, or -256)
|
-- AES cipher (aka Rijndael-128, -192, or -256)
|
||||||
--
|
--
|
||||||
-- ensure consistent test output regardless of the default bytea format
|
|
||||||
SET bytea_output TO escape;
|
|
||||||
|
|
||||||
-- some standard Rijndael testvalues
|
-- some standard Rijndael testvalues
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt(
|
||||||
decode('00112233445566778899aabbccddeeff', 'hex'),
|
'\x00112233445566778899aabbccddeeff',
|
||||||
decode('000102030405060708090a0b0c0d0e0f', 'hex'),
|
'\x000102030405060708090a0b0c0d0e0f',
|
||||||
'aes-ecb/pad:none'), 'hex');
|
'aes-ecb/pad:none');
|
||||||
|
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt(
|
||||||
decode('00112233445566778899aabbccddeeff', 'hex'),
|
'\x00112233445566778899aabbccddeeff',
|
||||||
decode('000102030405060708090a0b0c0d0e0f1011121314151617', 'hex'),
|
'\x000102030405060708090a0b0c0d0e0f1011121314151617',
|
||||||
'aes-ecb/pad:none'), 'hex');
|
'aes-ecb/pad:none');
|
||||||
|
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt(
|
||||||
decode('00112233445566778899aabbccddeeff', 'hex'),
|
'\x00112233445566778899aabbccddeeff',
|
||||||
decode('000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f', 'hex'),
|
'\x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f',
|
||||||
'aes-ecb/pad:none'), 'hex');
|
'aes-ecb/pad:none');
|
||||||
|
|
||||||
-- cbc
|
-- cbc
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt(
|
||||||
decode('00112233445566778899aabbccddeeff', 'hex'),
|
'\x00112233445566778899aabbccddeeff',
|
||||||
decode('000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f', 'hex'),
|
'\x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f',
|
||||||
'aes-cbc/pad:none'), 'hex');
|
'aes-cbc/pad:none');
|
||||||
|
|
||||||
-- key padding
|
-- key padding
|
||||||
|
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt(
|
||||||
decode('0011223344', 'hex'),
|
'\x0011223344',
|
||||||
decode('000102030405', 'hex'),
|
'\x000102030405',
|
||||||
'aes-cbc'), 'hex');
|
'aes-cbc');
|
||||||
|
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt(
|
||||||
decode('0011223344', 'hex'),
|
'\x0011223344',
|
||||||
decode('000102030405060708090a0b0c0d0e0f10111213', 'hex'),
|
'\x000102030405060708090a0b0c0d0e0f10111213',
|
||||||
'aes-cbc'), 'hex');
|
'aes-cbc');
|
||||||
|
|
||||||
SELECT encode(encrypt(
|
SELECT encrypt(
|
||||||
decode('0011223344', 'hex'),
|
'\x0011223344',
|
||||||
decode('000102030405060708090a0b0c0d0e0f101112131415161718191a1b', 'hex'),
|
'\x000102030405060708090a0b0c0d0e0f101112131415161718191a1b',
|
||||||
'aes-cbc'), 'hex');
|
'aes-cbc');
|
||||||
|
|
||||||
-- empty data
|
-- empty data
|
||||||
select encode(encrypt('', 'foo', 'aes'), 'hex');
|
select encrypt('', 'foo', 'aes');
|
||||||
-- 10 bytes key
|
-- 10 bytes key
|
||||||
select encode(encrypt('foo', '0123456789', 'aes'), 'hex');
|
select encrypt('foo', '0123456789', 'aes');
|
||||||
-- 22 bytes key
|
-- 22 bytes key
|
||||||
select encode(encrypt('foo', '0123456789012345678901', 'aes'), 'hex');
|
select encrypt('foo', '0123456789012345678901', 'aes');
|
||||||
|
|
||||||
-- decrypt
|
-- decrypt
|
||||||
select decrypt(encrypt('foo', '0123456', 'aes'), '0123456', 'aes');
|
select encode(decrypt(encrypt('foo', '0123456', 'aes'), '0123456', 'aes'), 'escape');
|
||||||
|
|
||||||
-- iv
|
-- iv
|
||||||
select encode(encrypt_iv('foo', '0123456', 'abcd', 'aes'), 'hex');
|
select encrypt_iv('foo', '0123456', 'abcd', 'aes');
|
||||||
select decrypt_iv(decode('2c24cb7da91d6d5699801268b0f5adad', 'hex'),
|
select encode(decrypt_iv('\x2c24cb7da91d6d5699801268b0f5adad', '0123456', 'abcd', 'aes'), 'escape');
|
||||||
'0123456', 'abcd', 'aes');
|
|
||||||
|
|
||||||
-- long message
|
-- long message
|
||||||
select encode(encrypt('Lets try a longer message.', '0123456789', 'aes'), 'hex');
|
select encrypt('Lets try a longer message.', '0123456789', 'aes');
|
||||||
select decrypt(encrypt('Lets try a longer message.', '0123456789', 'aes'), '0123456789', 'aes');
|
select encode(decrypt(encrypt('Lets try a longer message.', '0123456789', 'aes'), '0123456789', 'aes'), 'escape');
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
-- SHA1 message digest
|
-- SHA1 message digest
|
||||||
--
|
--
|
||||||
|
|
||||||
SELECT encode(digest('', 'sha1'), 'hex');
|
SELECT digest('', 'sha1');
|
||||||
SELECT encode(digest('a', 'sha1'), 'hex');
|
SELECT digest('a', 'sha1');
|
||||||
SELECT encode(digest('abc', 'sha1'), 'hex');
|
SELECT digest('abc', 'sha1');
|
||||||
SELECT encode(digest('message digest', 'sha1'), 'hex');
|
SELECT digest('message digest', 'sha1');
|
||||||
SELECT encode(digest('abcdefghijklmnopqrstuvwxyz', 'sha1'), 'hex');
|
SELECT digest('abcdefghijklmnopqrstuvwxyz', 'sha1');
|
||||||
SELECT encode(digest('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', 'sha1'), 'hex');
|
SELECT digest('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', 'sha1');
|
||||||
SELECT encode(digest('12345678901234567890123456789012345678901234567890123456789012345678901234567890', 'sha1'), 'hex');
|
SELECT digest('12345678901234567890123456789012345678901234567890123456789012345678901234567890', 'sha1');
|
||||||
|
@ -3,31 +3,31 @@
|
|||||||
--
|
--
|
||||||
|
|
||||||
-- SHA224
|
-- SHA224
|
||||||
SELECT encode(digest('', 'sha224'), 'hex');
|
SELECT digest('', 'sha224');
|
||||||
SELECT encode(digest('a', 'sha224'), 'hex');
|
SELECT digest('a', 'sha224');
|
||||||
SELECT encode(digest('abc', 'sha224'), 'hex');
|
SELECT digest('abc', 'sha224');
|
||||||
SELECT encode(digest('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq', 'sha224'), 'hex');
|
SELECT digest('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq', 'sha224');
|
||||||
SELECT encode(digest('12345678901234567890123456789012345678901234567890123456789012345678901234567890', 'sha224'), 'hex');
|
SELECT digest('12345678901234567890123456789012345678901234567890123456789012345678901234567890', 'sha224');
|
||||||
|
|
||||||
-- SHA256
|
-- SHA256
|
||||||
SELECT encode(digest('', 'sha256'), 'hex');
|
SELECT digest('', 'sha256');
|
||||||
SELECT encode(digest('a', 'sha256'), 'hex');
|
SELECT digest('a', 'sha256');
|
||||||
SELECT encode(digest('abc', 'sha256'), 'hex');
|
SELECT digest('abc', 'sha256');
|
||||||
SELECT encode(digest('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq', 'sha256'), 'hex');
|
SELECT digest('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq', 'sha256');
|
||||||
SELECT encode(digest('12345678901234567890123456789012345678901234567890123456789012345678901234567890', 'sha256'), 'hex');
|
SELECT digest('12345678901234567890123456789012345678901234567890123456789012345678901234567890', 'sha256');
|
||||||
|
|
||||||
-- SHA384
|
-- SHA384
|
||||||
SELECT encode(digest('', 'sha384'), 'hex');
|
SELECT digest('', 'sha384');
|
||||||
SELECT encode(digest('a', 'sha384'), 'hex');
|
SELECT digest('a', 'sha384');
|
||||||
SELECT encode(digest('abc', 'sha384'), 'hex');
|
SELECT digest('abc', 'sha384');
|
||||||
SELECT encode(digest('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq', 'sha384'), 'hex');
|
SELECT digest('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq', 'sha384');
|
||||||
SELECT encode(digest('abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu', 'sha384'), 'hex');
|
SELECT digest('abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu', 'sha384');
|
||||||
SELECT encode(digest('abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz', 'sha384'), 'hex');
|
SELECT digest('abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz', 'sha384');
|
||||||
|
|
||||||
-- SHA512
|
-- SHA512
|
||||||
SELECT encode(digest('', 'sha512'), 'hex');
|
SELECT digest('', 'sha512');
|
||||||
SELECT encode(digest('a', 'sha512'), 'hex');
|
SELECT digest('a', 'sha512');
|
||||||
SELECT encode(digest('abc', 'sha512'), 'hex');
|
SELECT digest('abc', 'sha512');
|
||||||
SELECT encode(digest('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq', 'sha512'), 'hex');
|
SELECT digest('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq', 'sha512');
|
||||||
SELECT encode(digest('abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu', 'sha512'), 'hex');
|
SELECT digest('abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu', 'sha512');
|
||||||
SELECT encode(digest('abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz', 'sha512'), 'hex');
|
SELECT digest('abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz', 'sha512');
|
||||||
|
Reference in New Issue
Block a user