summaryrefslogtreecommitdiffstats
path: root/contrib/pgcrypto/sql/pgp-pubkey-encrypt.sql
blob: 879b47f8712474421d7cf866cb893e25a5d97120 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
--
-- PGP Public Key Encryption
--
-- ensure consistent test output regardless of the default bytea format
SET bytea_output TO escape;

-- successful encrypt/decrypt
select pgp_pub_decrypt(
	pgp_pub_encrypt('Secret msg', dearmor(pubkey)),
	dearmor(seckey))
from keytbl where keytbl.id=1;

select pgp_pub_decrypt(
		pgp_pub_encrypt('Secret msg', dearmor(pubkey)),
		dearmor(seckey))
from keytbl where keytbl.id=2;

select pgp_pub_decrypt(
		pgp_pub_encrypt('Secret msg', dearmor(pubkey)),
		dearmor(seckey))
from keytbl where keytbl.id=3;

select pgp_pub_decrypt(
		pgp_pub_encrypt('Secret msg', dearmor(pubkey)),
		dearmor(seckey))
from keytbl where keytbl.id=6;

-- try with rsa-sign only
select pgp_pub_decrypt(
		pgp_pub_encrypt('Secret msg', dearmor(pubkey)),
		dearmor(seckey))
from keytbl where keytbl.id=4;

-- try with secret key
select pgp_pub_decrypt(
		pgp_pub_encrypt('Secret msg', dearmor(seckey)),
		dearmor(seckey))
from keytbl where keytbl.id=1;

-- does text-to-bytea works
select pgp_pub_decrypt_bytea(
		pgp_pub_encrypt('Secret msg', dearmor(pubkey)),
		dearmor(seckey))
from keytbl where keytbl.id=1;

-- and bytea-to-text?
select pgp_pub_decrypt(
		pgp_pub_encrypt_bytea('Secret msg', dearmor(pubkey)),
		dearmor(seckey))
from keytbl where keytbl.id=1;