def _parse_packet(cls, packet): if isinstance(packet, OpenPGP.Packet) or isinstance(packet, OpenPGP.Message) or isinstance(packet, RSAPublicKey) or isinstance(packet, RSAPrivateKey) or isinstance(packet, DSAPublicKey) or isinstance(packet, DSAPrivateKey): return packet elif isinstance(packet, tuple) or isinstance(packet, list): if sys.version_info[0] == 2 and isinstance(packet[0], int) or isinstance(packet[0], int): data = [] for i in packet: data.append(Crypto.Util.number.long_to_bytes(i)) # OpenPGP likes bytes else: data = packet return OpenPGP.SecretKeyPacket(keydata=data, algorithm=1, version=3) # V3 for fingerprint with no timestamp else: return OpenPGP.Message.parse(packet)
def testSigningKeysRSA(self): k = Crypto.PublicKey.RSA.generate(1024) nkey = OpenPGP.SecretKeyPacket((Crypto.Util.number.long_to_bytes(k.n), Crypto.Util.number.long_to_bytes(k.e), Crypto.Util.number.long_to_bytes(k.d), Crypto.Util.number.long_to_bytes(k.p), Crypto.Util.number.long_to_bytes(k.q), Crypto.Util.number.long_to_bytes(k.u))) uid = OpenPGP.UserIDPacket('Test <*****@*****.**>') wkey = OpenPGP.cryptography.Wrapper(nkey) m = wkey.sign_key_userid([nkey, uid]).to_bytes() reparsedM = OpenPGP.Message.parse(m) nose.tools.assert_equal(wkey.verify(reparsedM), reparsedM.signatures())
import Crypto.PublicKey.RSA import Crypto.Util.number import OpenPGP import OpenPGP.Crypto import sys k = Crypto.PublicKey.RSA.generate(1024) nkey = OpenPGP.SecretKeyPacket(( Crypto.Util.number.long_to_bytes(k.n), Crypto.Util.number.long_to_bytes(k.e), Crypto.Util.number.long_to_bytes(k.d), Crypto.Util.number.long_to_bytes(k.p), Crypto.Util.number.long_to_bytes(k.q), Crypto.Util.number.long_to_bytes(k.u) )) uid = OpenPGP.UserIDPacket('Test <*****@*****.**>') wkey = OpenPGP.Crypto.Wrapper(nkey) m = wkey.sign_key_userid([nkey, uid]) sys.stdout.write(m.to_bytes())