Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def makekey():
n = ok.getpub()
if len(n) == 128:
priv_key = pgpy.PGPKey.new(PubKeyAlgorithm.RSAEncryptOrSign, 1024)
if len(n) == 256:
priv_key = pgpy.PGPKey.new(PubKeyAlgorithm.RSAEncryptOrSign, 2048)
if len(n) == 384:
priv_key = pgpy.PGPKey.new(PubKeyAlgorithm.RSAEncryptOrSign, 3072)
if len(n) == 512:
priv_key = pgpy.PGPKey.new(PubKeyAlgorithm.RSAEncryptOrSign, 4096)
#uid = pgpy.PGPUID.new('Abraham Lincoln', comment='Honest Abe', email='abraham.lincoln@whitehouse.gov')
#priv_key.add_uid(uid, usage={KeyFlags.Sign}, hashes=[HashAlgorithm.SHA512, HashAlgorithm.SHA256],
# compression=[CompressionAlgorithm.BZ2, CompressionAlgorithm.Uncompressed],
# key_expires=timedelta(days=365))
#p = n[:(len(n)/2)]
#q = n[(len(n)/2):]
n = n.encode("HEX")
N = long(n, 16)
#p = p.encode("HEX")
#p = long(p, 16)
def makekey():
n = ok.getpub()
if len(n) == 128:
priv_key = pgpy.PGPKey.new(PubKeyAlgorithm.RSAEncryptOrSign, 1024)
if len(n) == 256:
priv_key = pgpy.PGPKey.new(PubKeyAlgorithm.RSAEncryptOrSign, 2048)
if len(n) == 384:
priv_key = pgpy.PGPKey.new(PubKeyAlgorithm.RSAEncryptOrSign, 3072)
if len(n) == 512:
priv_key = pgpy.PGPKey.new(PubKeyAlgorithm.RSAEncryptOrSign, 4096)
#uid = pgpy.PGPUID.new('Abraham Lincoln', comment='Honest Abe', email='abraham.lincoln@whitehouse.gov')
#priv_key.add_uid(uid, usage={KeyFlags.Sign}, hashes=[HashAlgorithm.SHA512, HashAlgorithm.SHA256],
# compression=[CompressionAlgorithm.BZ2, CompressionAlgorithm.Uncompressed],
# key_expires=timedelta(days=365))
#p = n[:(len(n)/2)]
#q = n[(len(n)/2):]
n = n.encode("HEX")
N = long(n, 16)
#p = p.encode("HEX")
#p = long(p, 16)
#q = q.encode("HEX")
#q = long(q, 16)
e = int('10001', 16)
#pub = rsatogpg(e,N,p,q,'Nikola Tesla')
#rsakey = custPubKeyV4(custRSAPub(N,e))
#priv_key._key = rsakey
def abe():
uid = PGPUID.new('Abraham Lincoln', comment='Honest Abe', email='abraham.lincoln@whitehouse.gov')
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
def test_new_key_unimplemented_alg(self, key_alg_unim):
with pytest.raises(NotImplementedError):
PGPKey.new(key_alg_unim, 512)
def makekey():
n = ok.getpub()
if len(n) == 128:
priv_key = pgpy.PGPKey.new(PubKeyAlgorithm.RSAEncryptOrSign, 1024)
if len(n) == 256:
priv_key = pgpy.PGPKey.new(PubKeyAlgorithm.RSAEncryptOrSign, 2048)
if len(n) == 384:
priv_key = pgpy.PGPKey.new(PubKeyAlgorithm.RSAEncryptOrSign, 3072)
if len(n) == 512:
priv_key = pgpy.PGPKey.new(PubKeyAlgorithm.RSAEncryptOrSign, 4096)
#uid = pgpy.PGPUID.new('Abraham Lincoln', comment='Honest Abe', email='abraham.lincoln@whitehouse.gov')
#priv_key.add_uid(uid, usage={KeyFlags.Sign}, hashes=[HashAlgorithm.SHA512, HashAlgorithm.SHA256],
# compression=[CompressionAlgorithm.BZ2, CompressionAlgorithm.Uncompressed],
# key_expires=timedelta(days=365))
#p = n[:(len(n)/2)]
#q = n[(len(n)/2):]
n = n.encode("HEX")
N = long(n, 16)
#p = p.encode("HEX")
#p = long(p, 16)
#q = q.encode("HEX")
#q = long(q, 16)
def _gen_skey_usage_all(self, emailadr):
skey = PGPKey.new(SKEY_ALG, KEY_SIZE)
# NOTE: pgpy implements separate attributes for name and e-mail
# address. Name is mandatory.
# Here e-mail address is used for the attribute name,
# so that the uid is 'e-mail adress'.
# If name attribute would be set to empty string
# and email to the e-mail address, the uid would be
# ' ', which we do not want.
uid = PGPUID.new(emailadr)
skey.add_uid(uid, usage=SKEY_USAGE_ALL, **SKEY_ARGS)
return skey