keygen.py 581 B

123456789101112131415161718192021222324
  1. import Crypto.PublicKey.RSA
  2. import Crypto.Util.number
  3. import OpenPGP
  4. import OpenPGP.Crypto
  5. import sys
  6. k = Crypto.PublicKey.RSA.generate(1024)
  7. nkey = OpenPGP.SecretKeyPacket((
  8. Crypto.Util.number.long_to_bytes(k.n),
  9. Crypto.Util.number.long_to_bytes(k.e),
  10. Crypto.Util.number.long_to_bytes(k.d),
  11. Crypto.Util.number.long_to_bytes(k.p),
  12. Crypto.Util.number.long_to_bytes(k.q),
  13. Crypto.Util.number.long_to_bytes(k.u)
  14. ))
  15. uid = OpenPGP.UserIDPacket('Test <test@example.com>')
  16. wkey = OpenPGP.Crypto.Wrapper(nkey)
  17. m = wkey.sign_key_userid([nkey, uid])
  18. sys.stdout.write(m.to_bytes())