本文整理汇总了Python中pgpy.PGPKey.new方法的典型用法代码示例。如果您正苦于以下问题:Python PGPKey.new方法的具体用法?Python PGPKey.new怎么用?Python PGPKey.new使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pgpy.PGPKey
的用法示例。
在下文中一共展示了PGPKey.new方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: temp_key
# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import new [as 别名]
def temp_key():
u = PGPUID.new('User')
k = PGPKey.new(PubKeyAlgorithm.RSAEncryptOrSign, 512)
k.add_uid(u, usage={KeyFlags.Certify, KeyFlags.Sign}, hashes=[HashAlgorithm.SHA1])
sk = PGPKey.new(PubKeyAlgorithm.RSAEncryptOrSign, 512)
k.add_subkey(sk, usage={KeyFlags.EncryptCommunications})
return k
示例2: test_add_subkey
# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import new [as 别名]
def test_add_subkey(self, pkspec, skspec):
if pkspec not in self.keys:
pytest.skip('Keyspec {} not in keys; must not have generated'.format(pkspec))
alg, size = skspec
if not alg.can_gen:
pytest.xfail('Key algorithm {} not yet supported'.format(alg.name))
if isinstance(size, EllipticCurveOID) and ((not size.can_gen) or size.name not in _openssl_get_supported_curves()):
pytest.xfail('Curve {} not yet supported'.format(size.name))
key = self.keys[pkspec]
subkey = PGPKey.new(*skspec)
# before adding subkey to key, the key packet should be a PrivKeyV4, not a PrivSubKeyV4
assert isinstance(subkey._key, PrivKeyV4)
assert not isinstance(subkey._key, PrivSubKeyV4)
key.add_subkey(subkey, usage={KeyFlags.EncryptCommunications})
# now that we've added it, it should be a PrivSubKeyV4
assert isinstance(subkey._key, PrivSubKeyV4)
# self-verify
assert key.verify(subkey)
sv = key.verify(key)
assert sv
assert subkey in sv
# try to verify with GPG
self.gpg_verify_key(key)
示例3: test_new_key_deprecated_rsa_alg
# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import new [as 别名]
def test_new_key_deprecated_rsa_alg(self, key_alg_rsa_depr, recwarn):
k = PGPKey.new(key_alg_rsa_depr, 512)
w = recwarn.pop()
assert str(w.message) == '{:s} is deprecated - generating key using RSAEncryptOrSign'.format(key_alg_rsa_depr.name)
# assert w.filename == __file__
assert k.key_algorithm == PubKeyAlgorithm.RSAEncryptOrSign
示例4: test_new_key
# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import new [as 别名]
def test_new_key(self, key_alg):
# create a key and a user id and add the UID to the key
uid = PGPUID.new('Hugo Gernsback', 'Science Fiction Plus', '[email protected]')
key = PGPKey.new(key_alg, key_alg_size[key_alg])
key.add_uid(uid, hashes=[HashAlgorithm.SHA224])
# self-verify the key
assert key.verify(key)
self.gen_keys[key_alg] = key
示例5: test_verify_invalid_sig
# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import new [as 别名]
def test_verify_invalid_sig(self, string, key_alg):
# generate a keypair
u = PGPUID.new('asdf')
k = PGPKey.new(key_alg, key_alg_size[key_alg])
k.add_uid(u, usage={KeyFlags.Certify, KeyFlags.Sign}, hashes=[HashAlgorithm.SHA1])
# sign string with extra characters (this means k.pubkey.verify(string) will return false
sig = k.sign(string + 'asdf')
assert not k.pubkey.verify(string, sig)
示例6: test_verify_invalid_sig
# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import new [as 别名]
def test_verify_invalid_sig(self, pkspec, string):
# test verifying an invalid signature
u = PGPUID.new('asdf')
k = PGPKey.new(*pkspec)
k.add_uid(u, usage={KeyFlags.Certify, KeyFlags.Sign}, hashes=[HashAlgorithm.SHA1])
# sign the string with extra characters, so that verifying just string fails
sig = k.sign(string + 'asdf')
sv = k.pubkey.verify(string, sig)
assert not sv
assert sig in sv
示例7: abe
# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import new [as 别名]
def abe():
uid = PGPUID.new('Abraham Lincoln', comment='Honest Abe', email='[email protected]')
with open('tests/testdata/abe.jpg', 'rb') as abef:
abebytes = bytearray(os.fstat(abef.fileno()).st_size)
abef.readinto(abebytes)
uphoto = PGPUID.new(abebytes)
# Abe is pretty oldschool, so he uses a DSA primary key
# normally he uses an ElGamal subkey for encryption, but PGPy doesn't support that yet, so he's settled for RSA for now
key = PGPKey.new(PubKeyAlgorithm.DSA, 1024)
subkey = PGPKey.new(PubKeyAlgorithm.RSAEncryptOrSign, 1024)
key.add_uid(uid,
usage={KeyFlags.Certify, KeyFlags.Sign},
hashes=[HashAlgorithm.SHA224, HashAlgorithm.SHA1],
ciphers=[SymmetricKeyAlgorithm.AES128, SymmetricKeyAlgorithm.Camellia128, SymmetricKeyAlgorithm.CAST5],
compression=[CompressionAlgorithm.ZLIB])
key.add_uid(uphoto)
key.add_subkey(subkey, usage={KeyFlags.EncryptCommunications, KeyFlags.EncryptStorage})
return key
示例8: test_encrypt_message_select_uid
# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import new [as 别名]
def test_encrypt_message_select_uid(self):
# generate a temporary key with two UIDs, then encrypt a message
u1 = PGPUID.new('UID One')
u2 = PGPUID.new('UID Two')
k = PGPKey.new(PubKeyAlgorithm.RSAEncryptOrSign, 512)
flags = {KeyFlags.Certify, KeyFlags.Sign, KeyFlags.EncryptCommunications, KeyFlags.EncryptStorage}
k.add_uid(u1, usage=flags, hashes=[HashAlgorithm.SHA1], ciphers=[SymmetricKeyAlgorithm.AES128])
k.add_uid(u2, usage=flags, hashes=[HashAlgorithm.SHA1], ciphers=[SymmetricKeyAlgorithm.Camellia128])
emsg = k.pubkey.encrypt(PGPMessage.new('This message is about to be encrypted'), user='UID Two')
# assert that it was encrypted with Camellia128 and that we can decrypt it normally
assert emsg._sessionkeys[0].decrypt_sk(k._key)[0] == SymmetricKeyAlgorithm.Camellia128
assert k.decrypt(emsg).message == 'This message is about to be encrypted'
示例9: test_new_subkey
# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import new [as 别名]
def test_new_subkey(self, key_alg):
key = self.gen_keys[key_alg]
subkey = PGPKey.new(subkey_alg[key_alg], key_alg_size[subkey_alg[key_alg]])
assert subkey._key
assert not isinstance(subkey._key, PrivSubKeyV4)
# now add the subkey to key and then verify it
key.add_subkey(subkey, usage={KeyFlags.EncryptCommunications})
# subkey should be a PrivSubKeyV4 now, not a PrivKeyV4
assert isinstance(subkey._key, PrivSubKeyV4)
# self-verify
sv = self.gen_keys[key_alg].verify(self.gen_keys[key_alg])
assert sv
assert subkey in sv
示例10: test_gen_key
# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import new [as 别名]
def test_gen_key(self, alg, size):
# create a primary key with a UID
uid = PGPUID.new('Test Key', '{}.{}'.format(alg.name, size), '[email protected]')
key = PGPKey.new(alg, size)
if alg is PubKeyAlgorithm.ECDSA:
# ECDSA keys require larger hash digests
key.add_uid(uid, hashes=[HashAlgorithm.SHA384])
else:
key.add_uid(uid, hashes=[HashAlgorithm.SHA224])
assert uid in key
# self-verify the key
assert key.verify(key)
self.keys[(alg, size)] = key
# try to verify with GPG
self.gpg_verify_key(key)
示例11: temp_subkey
# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import new [as 别名]
def temp_subkey():
return PGPKey.new(PubKeyAlgorithm.RSAEncryptOrSign, 512)
示例12: test_new_key_unimplemented_alg
# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import new [as 别名]
def test_new_key_unimplemented_alg(self, key_alg_unim):
with pytest.raises(NotImplementedError):
PGPKey.new(key_alg_unim, 512)
示例13: test_new_key_invalid_size
# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import new [as 别名]
def test_new_key_invalid_size(self, badkey):
key_alg, key_size = badkey
with pytest.raises(ValueError):
PGPKey.new(key_alg, key_size)
示例14: test_new_key_no_uid_action
# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import new [as 别名]
def test_new_key_no_uid_action(self):
key = PGPKey.new(PubKeyAlgorithm.RSAEncryptOrSign, 1024)
with pytest.raises(PGPError):
key.sign('asdf')