Issue with pgcrypto pgp_pub_encrypt



我一直在尝试在Postgres中测试pgcrypto扩展,但遇到了一些困难。当我尝试加密数据时,我会得到一个

ERROR:  No encryption key found
********** Error **********
ERROR: No encryption key found
SQL state: 39000

我用Kleopatra创建了一个酒吧/私人钥匙,但似乎不起作用。

测试表:

CREATE TABLE notes
(
  id serial NOT NULL,
  note bytea,
  description text,
  CONSTRAINT pk_notes PRIMARY KEY (id )
)
WITH (
  OIDS=FALSE
);

任何建议都非常棒。

这是我的插入代码:

INSERT INTO "notes"("note")
VALUES(pgp_pub_encrypt('This test data', dearmor(
'-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v2
mQENBFUNhxMBCADXMrvdx/UmVdH0ABZdmUIjCe3/lh7s7G6AFRjryFfuZbcj62//
LBxRq2QsONxuzNq8HIwssuLQxOtU9yqv5U49TGl4wuu+2jGorKnbDIKCIrM7tFpi
JSOeClsDJer9I+UrXbYQLSoN/nyYUxl5ColxnvmWnQagZH71L5eLKke/W4DJXcgW
N3Yt6vfi4wOFQ3IdVQeMP8b6ehZjbTU2+eDShvsLhkUYD5//OGjpshsBocnIvZBe
...
...
...
...
B/0SD4A2b6buRnwyDtJ+eTBjQTVT3ISSgTtwtmtLQvy4/3r95G/3UdB/+ZtB1ygB
H/1h9gh2NbonRS0uoIvhsy81/G+qXngnvuIL2K3SeDV5rF9AMEX1NWeoX73GhdD2
X6Er82DfC8cowqWge4yM55FRMo3k2Upjo004ofDmpj/wbJDspU/iDIUHWYv+upEJ
0yeVukQLaRe3/IMqd0lSHW0piDLP6FvG98suZOPZS6ivYCE1Y7cFUPxxPAZRvxVO
dXbPRUw8vBHBDHoJ8h+zcBz4kinj4I28gXNIzaMLZU6+Ju+GicAMwh3iS2TBSM8y
fZn+OwxJfeAUq9sw94A3hmPU
=2/+P
-----END PGP PUBLIC KEY BLOCK-----')));

更新:我想我可以使用Kleopatra来创建公共/私有对。不知怎么的,我得到了一把钥匙,但它们不起作用。当我使用gpg命令行创建密钥时,它起了作用。

非常直接:

gpg—gen密钥

回答问题
生成关键帧时,需要导出它们。

gpg—导出密钥-a";{您用来创建密钥的电子邮件}"gt;机密密钥

gpg—导出-a";{您用来创建密钥的电子邮件}"gt;公钥

我也遇到了一些麻烦,无法用新密钥重复,所以我想我会分享一下成功的方法:

从顶部

gpg --full-generate-key
# Real-Name: testname
# Email:
# Comment:
# Okay
# Passphrase: foobar
gpg --armor --export 'testname'
CREATE TEMPORARY TABLE foo_data (data BYTEA);
INSERT INTO foo_data
SELECT pgp_pub_encrypt('x', dearmor(
'-----BEGIN PGP PUBLIC KEY BLOCK-----
mQENBFz2w6IBCAC08MpF5wQlcNiuY3YYZx/c82cuIS09yIrw12bHGMOuCCL68l8+
czjCQi9fM8k1uGDKn8ttDuz+rtapweBqjNTrQGnoKrhShxM3pRwfUb/ieuDtjc84
vJU+P5FEV9Yh66ymzolBbY+r+8h9Zjc2fpawFlash7lfXXyvkGs0sorjsHETSyi8
0UyOsgbOxcHSHYeAqbazCL5QU5HTxrt1x5FI/0CWxsoFinMaiMEJrbYYMqfBC4TE
Hz0vwkd7drCk8tOMnJFxZNcGz5zRaJjloMCdt4NObQ048wfGJ7SKP0mNAb4oPnrn
dUsZAKfzQkUmHICzb7XEk/QJTrxsqSjN3U6PABEBAAG0CHRlc3RuYW1liQFOBBMB
CAA4FiEEAYV6IBG8fWXf/RvVwSQuiBgl2dwFAlz2w6ICGwMFCwkIBwIGFQoJCAsC
BBYCAwECHgECF4AACgkQwSQuiBgl2dwKcwgAsEA3rcKUncKR/P/vl3PD8XrV0der
f1M0XPuc8zaQqrPpIvdOpVfQ8uFkoDacr5uCWdH+qjaK7uxO+Tp/29TKHLxD4Ycx
sPFstKxjyE+dG4j57ddQJRei0O8mM7VvPUXx0LjqAwYb7PrGIBtXOB7m3DbvVVww
QeSLO49Z+wTLcXJiRw38wT/jSWAlNV3aPbfW0gTRoDLDUfOqjhCcULDfW08m/tvX
++Zgp4csXc3c4y3jpIpG82nkqFj6tYujab7lLUTcb+DOHJQecChG/JFTYlH3A0bY
InRB/JFFpvVd6dsz6ePB/rjTxz0lj2Fm0vnz1o9XCzOGMFwgwQhVuw9OArkBDQRc
9sOiAQgAq87Eh5oRnPXqzSKDhyH1yaBvGtnjM+Dk1PIn9SV4EC6oVoyPF4sMxx3o
c9kFmBucvhXWdLB6AJBIXWyx0jX3Ieopxis43FCzUVvxyyqo9ESD5ZCbRRz8Ftxe
W3GIlTD4+q/mvBVp8K0SHlDDbn/uevjwJcn1laKKO08e5FBtozjRwnTLys8Ybplu
32a7GWZq8KsknxJFo45MHmuHAysxlvhgsJJICAnRgVJ/jEoxb/Odbq3Vu6cOIfRS
j2yJVJcZM57txZiMmihEboTICeJNWooTUCuiWYtg2dNjniue38PHZImPe1MsDWuQ
52awPqjw2UBQKTgxjH8hDPYm7jjXIQARAQABiQE2BBgBCAAgFiEEAYV6IBG8fWXf
/RvVwSQuiBgl2dwFAlz2w6ICGwwACgkQwSQuiBgl2dwCHwgAhrwu7EFb52pMiHFn
fYmAB70varpA8ONX9o/OyrqcR1WR8Ew9wGZ6+uXK2+KTdz1Em0OsuK24DZjHJgPc
IADtymz/IQiclH6WWvpkZlkecITBV/OSXAK9bERcv0CjtHDW+B0piGf+ipdMy7kQ
+HbExKxKki9eiiO5iaH7QA/FRqoq7K3Ab4fAO36RuB2vKdNBPkDlwgIUBqjtQw2a
96wwwb50ra0eWH0ElGi3OhL5A3S06Wc0RmVAF+9XvT4pPH9t6fcQiGHQxKr6iFwF
PaF99Jtk5oR9JUg0DDK+nyY5NZ1OPMNakY4qThMV0fGpp3lLyBIW7RlQCXxj6j63
DgiBWQ==
=3n/6
-----END PGP PUBLIC KEY BLOCK-----'
)) AS data;
gpg --armor --export-secret-key 'testname'
SELECT pgp_pub_decrypt(data, dearmor(
'-----BEGIN PGP PRIVATE KEY BLOCK-----
lQPGBFz2w6IBCAC08MpF5wQlcNiuY3YYZx/c82cuIS09yIrw12bHGMOuCCL68l8+
czjCQi9fM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oqXTMu5
EPh2xMSsSpIvXoojuYmh+0APxUaqKuytwG+HwDt+kbgdrynTQT5A5cICFAao7UMN
mvesMMG+dK2tHlh9BJRotzoS+QN0tOlnNEZlQBfvV70+KTx/ben3EIhh0MSq+ohc
BT2hffSbZOaEfSVINAwyvp8mOTWdTjzDWpGOKk4TFdHxqad5S8gSFu0ZUAl8Y+o+
tw4IgVk=
=pUwd
-----END PGP PRIVATE KEY BLOCK-----'
), 'foobar') AS data FROM foo_data;

奖励:使用环境和postgres变量

set pgp_public_key `gpg --armor --export 'Test User'`
SELECT :'pgp_public_key';
set pgp_private_key `echo "$PGP_PRIVATE_KEY"`
SELECT :'pgp_private_key';

相关内容

  • 没有找到相关文章

最新更新