Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def rsa_sec():
return PGPKey.from_file('tests/testdata/keys/rsa.1.sec.asc')[0]
"+b4enZ/Z6qehoAdY1t4QYmA2PebKuerBXjIF1RWsPQDpu3GIZw4oBbdu5oUGB4I9\n" \
"yIepindM2b2I9dlY3ct4uhRbBmXPFcslmJ1K4pCurXvr4Po4DCcWqUmsGUQQbI1G\n" \
"UyAzSad7u9y3CRqhHFwzyFRRfl+/mgB2a6XvbGlG5Dkp1g7T/HIVJu+zv58AQkFw\n" \
"+ABuWNKCXa3TB51bkiBQlkRTSAu2tVZ8hVGZE+wUw0o9rLiy6mldFvbLABEBAAGJ\n" \
"AR8EGAEKAAkFAlOaNYoCGwwACgkQwPIhDg8ZPc1uDwf/SGoiZHjUsTWm4gZgZCzA\n" \
"jOpZs7dKjLL8Wm5G3HTFIGX0O8HCzQJARWq05N6EYmI4nPXxu08ba30SubybSeFU\n" \
"+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
signature = sk.__key__.__privkey__().sign(hdata, padding.PKCS1v15(), hashes.SHA512())
sig._signature.signature.from_signer(signature)
def setUp(self):
self.quedex_private_key = pgpy.PGPKey()
self.quedex_private_key.parse(open('keys/quedex-private-key.asc', 'r').read())
self.trader_public_key = pgpy.PGPKey()
self.trader_public_key.parse(open('keys/trader-public-key.asc', 'r').read())
trader = Trader('123456789', open('keys/trader-private-key.asc', 'r').read())
trader.decrypt_private_key('aaa')
exchange = Exchange(open('keys/quedex-public-key.asc', 'r').read(), 'wss://url')
self.listener = TestListener()
self.user_stream = UserStream(exchange, trader)
self.user_stream.add_listener(self.listener)
self.sent_message = None
def set_sent_message(message):
self.sent_message = message
self.user_stream.send_message = set_sent_message
args = 'key'
argvals = [ key
for k in TestFiles.keys
for key in PGPKeyBlock.load('tests/testdata/' + k)._keys
if isinstance(key, PGPKey) and
isinstance(key._keypkt, Primary) ]
# argvals = [ PGPKey.load('tests/testdata/' + k) for k in TestFiles.keys ]
if 'enc_key' in metafunc.fixturenames:
ids = TestFiles.ids(TestFiles.protected_privkeys)
args = 'enc_key'
argvals = [ key
for k in TestFiles.protected_privkeys
for key in PGPKeyBlock.load('tests/testdata/' + k)._keys
if isinstance(key, PGPKey) and
key.primary ]
metafunc.parametrize(args, argvals, ids=ids, scope="module")
"-----END PGP PRIVATE KEY BLOCK-----\n"
msg = "-----BEGIN PGP MESSAGE-----\n" \
"Version: PGPy v0.4.2\n" \
"\n" \
"xA0DAAIBPpLc6ocmOSwAwUwDDYjwqQ5XOH8BAfwOTH6C/lk5bQevArYnrf0q3Dde\n" \
"JDjM/otBckiTS8kvFz1XFfQhIDkZl+fDcRwDFNe9+JKLqOM4jU6FIUwToYgz0ksB\n" \
"f6iZ80U0dzHGtvmEzYSnsYWAglik0ch/E9tyNq/lryrLnrxWu7V26wPfI1TISuKd\n" \
"U+w1HPGoH8ugo6GkeqBdeED6gJfKEm1qgrHCXAQAAQIABgUCWUrVMQAKCRA+ktzq\n" \
"hyY5LLcHAgDHYjKVbpd5/FV4+CZ0H5yTnrD/vZ+QebDC7CmOM7f1Q5L1AdG/K1rr\n" \
"+Ud/YHq3NVk5UGU0LDfjdBwVaJmOjEUx\n" \
"=ITfp\n" \
"-----END PGP MESSAGE-----\n"
dkey, _ = PGPKey.from_blob(decrypt_key)
skey, _ = PGPKey.from_blob(sign_key)
encmsg = PGPMessage.from_blob(msg)
# this should work
decmsg = dkey.decrypt(encmsg)
assert decmsg.message == "Regression Test for PR#183"
# this should raise PGPError, not PGPDecryptionError
with pytest.raises(PGPError):
skey.decrypt(encmsg)
#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
return priv_key
# we can start by generating a primary key. For this example, we'll use RSA, but it could be DSA or ECDSA as well
#with open('test_priv.asc', 'rb') as f:
# t = f.read().replace('\r', '')
#priv_key, _ = PGPKey.from_blob(t)
priv_key = pgpy.PGPKey()
# we now have some key material, but our new key doesn't have a user ID yet, and therefore is not yet usable!
#with priv_key.unlock("test"):
# uid = pgpy.PGPUID.new('Abraham Lincoln', comment='Honest Abe', email='abraham.lincoln@whitehouse.gov')
# now we must add the new user id to the key. We'll need to specify all of our preferences at this point
# because PGPy doesn't have any built-in key preference defaults at this time
# this example is similar to GnuPG 2.1.x defaults, with no expiration or preferred keyserver
#priv_key.add_uid(uid, usage={KeyFlags.Sign, KeyFlags.EncryptCommunications, KeyFlags.EncryptStorage},
# hashes=[HashAlgorithm.SHA256, HashAlgorithm.SHA384, HashAlgorithm.SHA512, HashAlgorithm.SHA224],
# ciphers=[SymmetricKeyAlgorithm.AES256, SymmetricKeyAlgorithm.AES192, SymmetricKeyAlgorithm.AES128],
# compression=[CompressionAlgorithm.ZLIB, CompressionAlgorithm.BZ2, CompressionAlgorithm.ZIP, CompressionAlgorithm.Uncompressed])
print
print 'Do you want to sign or decrypt a message?'
print 's = sign, d = decrypt'
print
def _parse_key(self):
self._private_key = pgpy.PGPKey()
self._private_key.parse(self._private_key_str)