| 1 |
-- |
| 2 |
-- PGP Public Key Encryption |
| 3 |
-- |
| 4 |
-- successful encrypt/decrypt |
| 5 |
select pgp_pub_decrypt( |
| 6 |
pgp_pub_encrypt('Secret msg', dearmor(pubkey)), |
| 7 |
dearmor(seckey)) |
| 8 |
from keytbl where keytbl.id=1; |
| 9 |
pgp_pub_decrypt |
| 10 |
----------------- |
| 11 |
Secret msg |
| 12 |
(1 row) |
| 13 |
|
| 14 |
select pgp_pub_decrypt( |
| 15 |
pgp_pub_encrypt('Secret msg', dearmor(pubkey)), |
| 16 |
dearmor(seckey)) |
| 17 |
from keytbl where keytbl.id=2; |
| 18 |
pgp_pub_decrypt |
| 19 |
----------------- |
| 20 |
Secret msg |
| 21 |
(1 row) |
| 22 |
|
| 23 |
select pgp_pub_decrypt( |
| 24 |
pgp_pub_encrypt('Secret msg', dearmor(pubkey)), |
| 25 |
dearmor(seckey)) |
| 26 |
from keytbl where keytbl.id=3; |
| 27 |
pgp_pub_decrypt |
| 28 |
----------------- |
| 29 |
Secret msg |
| 30 |
(1 row) |
| 31 |
|
| 32 |
select pgp_pub_decrypt( |
| 33 |
pgp_pub_encrypt('Secret msg', dearmor(pubkey)), |
| 34 |
dearmor(seckey)) |
| 35 |
from keytbl where keytbl.id=6; |
| 36 |
pgp_pub_decrypt |
| 37 |
----------------- |
| 38 |
Secret msg |
| 39 |
(1 row) |
| 40 |
|
| 41 |
-- try with rsa-sign only |
| 42 |
select pgp_pub_decrypt( |
| 43 |
pgp_pub_encrypt('Secret msg', dearmor(pubkey)), |
| 44 |
dearmor(seckey)) |
| 45 |
from keytbl where keytbl.id=4; |
| 46 |
ERROR: No encryption key found |
| 47 |
-- try with secret key |
| 48 |
select pgp_pub_decrypt( |
| 49 |
pgp_pub_encrypt('Secret msg', dearmor(seckey)), |
| 50 |
dearmor(seckey)) |
| 51 |
from keytbl where keytbl.id=1; |
| 52 |
ERROR: Refusing to encrypt with secret key |
| 53 |
-- does text-to-bytea works |
| 54 |
select encode(pgp_pub_decrypt_bytea( |
| 55 |
pgp_pub_encrypt('Secret msg', dearmor(pubkey)), |
| 56 |
dearmor(seckey)), 'escape') |
| 57 |
from keytbl where keytbl.id=1; |
| 58 |
encode |
| 59 |
------------ |
| 60 |
Secret msg |
| 61 |
(1 row) |
| 62 |
|
| 63 |
-- and bytea-to-text? |
| 64 |
select pgp_pub_decrypt( |
| 65 |
pgp_pub_encrypt_bytea('Secret msg', dearmor(pubkey)), |
| 66 |
dearmor(seckey)) |
| 67 |
from keytbl where keytbl.id=1; |
| 68 |
ERROR: Not text data |