2005-03-21 13:24:52 +08:00
|
|
|
--
|
|
|
|
-- 3DES cipher
|
|
|
|
--
|
2009-08-05 04:10:00 +08:00
|
|
|
-- ensure consistent test output regardless of the default bytea format
|
|
|
|
SET bytea_output TO escape;
|
2005-03-21 13:24:52 +08:00
|
|
|
-- test vector from somewhere
|
|
|
|
SELECT encode(encrypt(
|
|
|
|
decode('80 00 00 00 00 00 00 00', 'hex'),
|
|
|
|
decode('01 01 01 01 01 01 01 01
|
|
|
|
01 01 01 01 01 01 01 01
|
|
|
|
01 01 01 01 01 01 01 01', 'hex'),
|
|
|
|
'3des-ecb/pad:none'), 'hex');
|
|
|
|
encode
|
|
|
|
------------------
|
|
|
|
95f8a5e5dd31d900
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- val 95 F8 A5 E5 DD 31 D9 00
|
|
|
|
select encode( encrypt('', 'foo', '3des'), 'hex');
|
|
|
|
encode
|
|
|
|
------------------
|
2005-07-06 02:15:36 +08:00
|
|
|
752111e37a2d7ac3
|
2005-03-21 13:24:52 +08:00
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- 10 bytes key
|
|
|
|
select encode( encrypt('foo', '0123456789', '3des'), 'hex');
|
|
|
|
encode
|
|
|
|
------------------
|
2005-07-06 02:15:36 +08:00
|
|
|
d2fb8baa1717cb02
|
2005-03-21 13:24:52 +08:00
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- 22 bytes key
|
|
|
|
select encode( encrypt('foo', '0123456789012345678901', '3des'), 'hex');
|
|
|
|
encode
|
|
|
|
------------------
|
|
|
|
a44360e699269817
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- decrypt
|
|
|
|
select decrypt(encrypt('foo', '0123456', '3des'), '0123456', '3des');
|
|
|
|
decrypt
|
|
|
|
---------
|
|
|
|
foo
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- iv
|
|
|
|
select encode(encrypt_iv('foo', '0123456', 'abcd', '3des'), 'hex');
|
|
|
|
encode
|
|
|
|
------------------
|
2005-07-06 02:15:36 +08:00
|
|
|
50735067b073bb93
|
2005-03-21 13:24:52 +08:00
|
|
|
(1 row)
|
|
|
|
|
2005-07-06 02:15:36 +08:00
|
|
|
select decrypt_iv(decode('50735067b073bb93', 'hex'), '0123456', 'abcd', '3des');
|
2005-03-21 13:24:52 +08:00
|
|
|
decrypt_iv
|
|
|
|
------------
|
|
|
|
foo
|
|
|
|
(1 row)
|
|
|
|
|
2005-07-13 04:27:45 +08:00
|
|
|
-- long message
|
|
|
|
select encode(encrypt('Lets try a longer message.', '0123456789012345678901', '3des'), 'hex');
|
|
|
|
encode
|
|
|
|
------------------------------------------------------------------
|
|
|
|
b71e3422269d0ded19468f33d65cd663c28e0871984792a7b3ba0ddcecec8d2c
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select decrypt(encrypt('Lets try a longer message.', '0123456789012345678901', '3des'), '0123456789012345678901', '3des');
|
|
|
|
decrypt
|
|
|
|
----------------------------
|
|
|
|
Lets try a longer message.
|
|
|
|
(1 row)
|
|
|
|
|