mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-08-28 16:17:20 +02:00
127 lines
3.5 KiB
Plaintext
127 lines
3.5 KiB
Plaintext
--
|
|
-- AES / Rijndael-128 cipher
|
|
--
|
|
-- ensure consistent test output regardless of the default bytea format
|
|
SET bytea_output TO escape;
|
|
-- some standard Rijndael testvalues
|
|
SELECT encode(encrypt(
|
|
decode('00112233445566778899aabbccddeeff', 'hex'),
|
|
decode('000102030405060708090a0b0c0d0e0f', 'hex'),
|
|
'aes-ecb/pad:none'), 'hex');
|
|
encode
|
|
----------------------------------
|
|
69c4e0d86a7b0430d8cdb78070b4c55a
|
|
(1 row)
|
|
|
|
SELECT encode(encrypt(
|
|
decode('00112233445566778899aabbccddeeff', 'hex'),
|
|
decode('000102030405060708090a0b0c0d0e0f1011121314151617', 'hex'),
|
|
'aes-ecb/pad:none'), 'hex');
|
|
encode
|
|
----------------------------------
|
|
dda97ca4864cdfe06eaf70a0ec0d7191
|
|
(1 row)
|
|
|
|
SELECT encode(encrypt(
|
|
decode('00112233445566778899aabbccddeeff', 'hex'),
|
|
decode('000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f', 'hex'),
|
|
'aes-ecb/pad:none'), 'hex');
|
|
encode
|
|
----------------------------------
|
|
8ea2b7ca516745bfeafc49904b496089
|
|
(1 row)
|
|
|
|
-- cbc
|
|
SELECT encode(encrypt(
|
|
decode('00112233445566778899aabbccddeeff', 'hex'),
|
|
decode('000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f', 'hex'),
|
|
'aes-cbc/pad:none'), 'hex');
|
|
encode
|
|
----------------------------------
|
|
8ea2b7ca516745bfeafc49904b496089
|
|
(1 row)
|
|
|
|
-- key padding
|
|
SELECT encode(encrypt(
|
|
decode('0011223344', 'hex'),
|
|
decode('000102030405', 'hex'),
|
|
'aes-cbc'), 'hex');
|
|
encode
|
|
----------------------------------
|
|
189a28932213f017b246678dbc28655f
|
|
(1 row)
|
|
|
|
SELECT encode(encrypt(
|
|
decode('0011223344', 'hex'),
|
|
decode('000102030405060708090a0b0c0d0e0f10111213', 'hex'),
|
|
'aes-cbc'), 'hex');
|
|
encode
|
|
----------------------------------
|
|
3b02279162d15580e069d3a71407a556
|
|
(1 row)
|
|
|
|
SELECT encode(encrypt(
|
|
decode('0011223344', 'hex'),
|
|
decode('000102030405060708090a0b0c0d0e0f101112131415161718191a1b', 'hex'),
|
|
'aes-cbc'), 'hex');
|
|
encode
|
|
----------------------------------
|
|
4facb6a041d53e0a5a73289170901fe7
|
|
(1 row)
|
|
|
|
-- empty data
|
|
select encode(encrypt('', 'foo', 'aes'), 'hex');
|
|
encode
|
|
----------------------------------
|
|
b48cc3338a2eb293b6007ef72c360d48
|
|
(1 row)
|
|
|
|
-- 10 bytes key
|
|
select encode(encrypt('foo', '0123456789', 'aes'), 'hex');
|
|
encode
|
|
----------------------------------
|
|
f397f03d2819b7172b68d0706fda4693
|
|
(1 row)
|
|
|
|
-- 22 bytes key
|
|
select encode(encrypt('foo', '0123456789012345678901', 'aes'), 'hex');
|
|
encode
|
|
----------------------------------
|
|
5c9db77af02b4678117bcd8a71ae7f53
|
|
(1 row)
|
|
|
|
-- decrypt
|
|
select decrypt(encrypt('foo', '0123456', 'aes'), '0123456', 'aes');
|
|
decrypt
|
|
---------
|
|
foo
|
|
(1 row)
|
|
|
|
-- iv
|
|
select encode(encrypt_iv('foo', '0123456', 'abcd', 'aes'), 'hex');
|
|
encode
|
|
----------------------------------
|
|
2c24cb7da91d6d5699801268b0f5adad
|
|
(1 row)
|
|
|
|
select decrypt_iv(decode('2c24cb7da91d6d5699801268b0f5adad', 'hex'),
|
|
'0123456', 'abcd', 'aes');
|
|
decrypt_iv
|
|
------------
|
|
foo
|
|
(1 row)
|
|
|
|
-- long message
|
|
select encode(encrypt('Lets try a longer message.', '0123456789', 'aes'), 'hex');
|
|
encode
|
|
------------------------------------------------------------------
|
|
d9beb785dd5403ed02f66b755bb191b93ed93ca54930153f2c3b9ec7785056ad
|
|
(1 row)
|
|
|
|
select decrypt(encrypt('Lets try a longer message.', '0123456789', 'aes'), '0123456789', 'aes');
|
|
decrypt
|
|
----------------------------
|
|
Lets try a longer message.
|
|
(1 row)
|
|
|