本文整理汇总了Python中pgpy.PGPKey.parse方法的典型用法代码示例。如果您正苦于以下问题:Python PGPKey.parse方法的具体用法?Python PGPKey.parse怎么用?Python PGPKey.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pgpy.PGPKey
的用法示例。
在下文中一共展示了PGPKey.parse方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_parse_wrong_crc24
# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import parse [as 别名]
def test_parse_wrong_crc24(self, recwarn):
keytext = _read('tests/testdata/keys/rsa.1.sec.asc').splitlines()
keytext[-2] = "=abcd"
keytext = '\n'.join(keytext)
key = PGPKey()
key.parse(keytext)
w = recwarn.pop(UserWarning)
assert str(w.message) == "Incorrect crc24"
assert w.filename == __file__
示例2: test_parse_wrong_magic
# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import parse [as 别名]
def test_parse_wrong_magic(self):
keytext = _read('tests/testdata/keys/rsa.1.sec.asc').replace('KEY', 'EKY')
key = PGPKey()
with pytest.raises(ValueError):
key.parse(keytext)
示例3: test_reg_bug_56
# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import parse [as 别名]
#.........这里部分代码省略.........
"f/wgDDWErfGIMaaruAIr0G05p4Q2G/NLgBccowSgFFfWprg3zfNPEQhH/qNs8O5m\n" \
"ByniMZk4n2TsKGlX6eT9RrfJVQhSLoQXxYikMtiZTki4yPUhTQev62KWHQcY6zNV\n" \
"2p9VQ24NUhVCIBnZ0CLkm38QFsS5flWVGat5kraHTXxvffz7yGHJiFkinQOYBFOa\n" \
"NYoBCADBPjB83l1O2m/Nr5KDm6/BwKfrRsoJDmMZ8nNHNUc/zK4RI4EFKkr35PSm\n" \
"gbA8yOlaSDWVz9zuKyOtb8Nohct2/lrac8zI+b4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+iAPymqm2YNXrE2RwLWko78M0r9enUep6SvbGKnukPG7lz/33PsxIVyATfMmcmzV\n" \
"4chyC7pICTwgHv/zC3S/k7GoS82Z39LO4R4aDa4aubNq6mx4eHUd0MSnYud1IzRx\n" \
"D8cPxh9fCdoW0OpddqKNczAvO4bl5wwDafrEa7HpIX/sMVMZXo2h6TkitdLCdEfk\n" \
"tgEjS0hTsFtfwsXt9TKi1x3HJIbcm8t78ubpWXepB/iNKVzv4punFHhKiz54ZFyN\n" \
"dQ==\n" \
"=lqIH\n" \
"-----END PGP PUBLIC KEY BLOCK-----\n"
# load the keypair above
sk = PGPKey()
sk.parse(sec)
pk = PGPKey()
pk.parse(pub)
sigsubject = bytearray(b"Hello!I'm a test document.I'm going to get signed a bunch of times.KBYE!")
sig = PGPSignature.new(SignatureType.BinaryDocument, PubKeyAlgorithm.RSAEncryptOrSign, HashAlgorithm.SHA512,
sk.fingerprint.keyid)
sig._signature.subpackets['h_CreationTime'][-1].created = datetime(2014, 8, 6, 23, 28, 51)
sig._signature.subpackets.update_hlen()
hdata = sig.hashdata(sigsubject)
sig._signature.hash2 = hashlib.new('sha512', hdata).digest()[:2]
# create the signature
signer = sk.__key__.__privkey__().signer(padding.PKCS1v15(), hashes.SHA512())
signer.update(hdata)
sig._signature.signature.from_signer(signer.finalize())
sig._signature.update_hlen()
# check encoding
assert sig._signature.signature.md_mod_n.to_mpibytes()[2:3] != b'\x00'
# with PGPy
assert pk.verify(sigsubject, sig)
# with GnuPG
with gpg.Context(armor=True, offline=True) as c:
c.set_engine_info(gpg.constants.PROTOCOL_OpenPGP, home_dir=gnupghome)
# import the key
key_data = gpg.Data(string=pub)
gpg.core.gpgme.gpgme_op_import(c.wrapped, key_data)
_, vres = c.verify(gpg.Data(string=sigsubject.decode('latin-1')), gpg.Data(string=str(sig)))
assert vres