import gnupg
import sys
gpg = gnupg.GPG(gnupghome="c:\\gpg")
enc="rsa-1024"
password="password"
user="Fred Bloggs"
email="fred@home.com"
if (len(sys.argv)>1):
enc=str(sys.argv[1])
if (len(sys.argv)>2):
password=str(sys.argv[2])
if (len(sys.argv)>3):
user=str(sys.argv[3])
if (len(sys.argv)>4):
email=str(sys.argv[4])
input_data = gpg.gen_key_input(key_type="RSA",key_length=1024,passphrase=password,name_real=user,name_email=email)
if (enc=="ecdsa-p256"):
input_data = gpg.gen_key_input(key_type="ECDSA",key_curve='nistp256',passphrase=password,name_real=user,name_email=email)
if (enc=="ecdsa-p384"):
input_data = gpg.gen_key_input(key_type="ECDSA",key_curve='nistp384',passphrase=password,name_real=user,name_email=email)
if (enc=="ecdsa-p521"):
input_data = gpg.gen_key_input(key_type="ECDSA",key_curve='nistp521',passphrase=password,name_real=user,name_email=email)
if (enc=="ecdsa-secp256k1"):
input_data = gpg.gen_key_input(key_type="ECDSA",key_curve='secp256k1',passphrase=password,name_real=user,name_email=email)
if (enc=="eddsa"):
input_data = gpg.gen_key_input(key_type="EDDSA",key_curve='ed25519',passphrase=password,name_real=user,name_email=email)
if (enc=="rsa-1024"):
input_data = gpg.gen_key_input(key_type="RSA",key_length=1024,passphrase=password,name_real=user,name_email=email)
if (enc=="rsa-2048"):
input_data = gpg.gen_key_input(key_type="RSA",key_length=2048,passphrase=password,name_real=user,name_email=email)
if (enc=="rsa-3072"):
input_data = gpg.gen_key_input(key_type="RSA",key_length=3072,passphrase=password,name_real=user,name_email=email)
key = gpg.gen_key(input_data)
fp = key.fingerprint
print ("Key ID: ",fp)
print ("Type: ",enc)
ascii_armored_public_keys = gpg.export_keys(fp)
print("Public key:\n",ascii_armored_public_keys.replace(chr(13),''))
ascii_armored_private_keys = gpg.export_keys(fp,True,passphrase=password)
print("Private key:\n",ascii_armored_private_keys.replace(chr(13),''))
print("Private key deleted: ",gpg.delete_keys(fp,True,passphrase=password))
print("Public key deleted: ",gpg.delete_keys(fp))
RSA-1024 的示例运行:
Key ID: E2728597FE4C56AB211B40F9DCDFA59903EB6813
Type: rsa-1024
Public key:
-----BEGIN PGP PUBLIC KEY BLOCK-----
mI0EY+oDWgEEALwMAM1SefOei3tcrzyaxE/ibdfbfcJCo+eA4PwpHOPiiH2mQYyU
mLqBLLt/F+rdDJY4mDKYkmPreObvhGp2meGpUyDf01d9jANQx0EIWDju3KXA9EdE
3Lp+QFhQWSYA/rgIrME2pAShn2bxF2ESM83XYPW30h5D2DRj94OJe7ShABEBAAG0
G0ZyZWQgQmxvZ2dzIDxmcmVkQGhvbWUuY29tPojRBBMBCAA7FiEE4nKFl/5MVqsh
G0D53N+lmQPraBMFAmPqA1oCGy8FCwkIBwICIgIGFQoJCAsCBBYCAwECHgcCF4AA
CgkQ3N+lmQPraBOnrAP/c1NDE4OTPRJp8SkRUPMwQjStu/jnJ6fEM5NoyDy1iQPJ
wxW7YkLPvAPhbPoExWhIenKeqeH8PaVdqSCt7tr04WjamQiGf66OVqjetPb3hOqv
S/eScHlg9qd68SxIhVoPNWb/Zzt7E94QNS3ZZsleyTj09HrlKKM5DbjJoW9oxdI=
=IiJW
-----END PGP PUBLIC KEY BLOCK-----
Private key:
-----BEGIN PGP PRIVATE KEY BLOCK-----
lQIGBGPqA1oBBAC8DADNUnnznot7XK88msRP4m3X233CQqPngOD8KRzj4oh9pkGM
lJi6gSy7fxfq3QyWOJgymJJj63jm74RqdpnhqVMg39NXfYwDUMdBCFg47tylwPRH
RNy6fkBYUFkmAP64CKzBNqQEoZ9m8RdhEjPN12D1t9IeQ9g0Y/eDiXu0oQARAQAB
/gcDAglYHcBL14Lgygpw6MCoYwGazwihMaRjG/brI9EC7iiJTZJXCn4o3OqPdHN+
9fyUziDyXN0DtEZoGK2s9PRtbeH8Rg7Wbd7Cry5FFlUdlkUTZdEVKdbgDT0ROe0I
4ohWn+B423+rDDtY+MD1qyegalLMXuDhsGnZrg73zfFwOOjkmsrImU2B3rC4XQBp
vCfIfFUub8oNw9cTnmsNUAGjWZ3tkMoYlRTq6c5vNdn4TvW7Vb9eegDKu2hSTGFL
/ORn9NknTzs/HavhZN/61bryZQCGXdLfeXtg+dMfu8AHEUCuCDoz+C/79RGatqyS
O9d9vZ3AO/JsbMegiURK1DY+gVAfVnPRTJCBipo0wnJ5XjejZijw3VGxtmt87A5i
0UzUzh7kO2xXOV1qXCkYwoSTo53Ognfe+4wgmky6bSfMVXCpsx/dyDPjO4VrZFmQ
uV8H7fJp4R8BACINj16lzPn/bbFQCgWYbmjUivio7KhNCiJABvDp+S60G0ZyZWQg
QmxvZ2dzIDxmcmVkQGhvbWUuY29tPojRBBMBCAA7FiEE4nKFl/5MVqshG0D53N+l
mQPraBMFAmPqA1oCGy8FCwkIBwICIgIGFQoJCAsCBBYCAwECHgcCF4AACgkQ3N+l
mQPraBOnrAP/c1NDE4OTPRJp8SkRUPMwQjStu/jnJ6fEM5NoyDy1iQPJwxW7YkLP
vAPhbPoExWhIenKeqeH8PaVdqSCt7tr04WjamQiGf66OVqjetPb3hOqvS/eScHlg
9qd68SxIhVoPNWb/Zzt7E94QNS3ZZsleyTj09HrlKKM5DbjJoW9oxdI=
=XA59
-----END PGP PRIVATE KEY BLOCK-----
Key ID: 3F3151C450A6075E643D1AA32D3C1A6A46928499
Type: rsa-2048
Public key:
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQENBGPqBQQBCACpEKQ6DUn7FOTDB203cPBX5PCodxQ37x9la5ich0yoKtU71l9U
mpwuncTZaFrtNsML7xUuC5WvMvclgX5ELCkMuX+mdvi/rMBQBMrbuYKw/3+/IhjJ
JBwMmJVRI6f2oQrlHYeJEE2m0oyUyiMaWiKoi8xMmik1UGCOh22taKrcMXqwkdO2
UO42na6b0GaswHcToGaC0ZA53Rh80sjP6lMEJbxMd8gB4jf8Q0PXQKtmANKA9hMv
8rPiCuA97p4sCkFRaKoIH6Yaiz2ePC1KoqAmn0be50e4ruaBh8R6EOIOnG0h8WdN
GpT/IbLLBhphFRyZV9R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xui/+ykFjCTlojyEJdBGYMFn0tZF1iUVkFg4Taa1tKu39/5w8e6FSRrM3qq64
l0sdh2FwurYZ36EvZqneXNSSQ6sPTpd9oJGnv0ofsG4K+33f9UfsoLA5VpLt+Do0
fkbqSbaUjofEHOXIhwaPsPC1qRJgjV2e49XtgYEM/nRhZ+3jaJ0pg11uEhRferkx
DqjhHj1Pq/lvctEL0tqdjEFQHnE7KgdAiKedUQm/53o8gMjsn5FsHM5j
=xPNy
-----END PGP PRIVATE KEY BLOCK-----
-----BEGIN PGP PUBLIC KEY BLOCK-----PUBLIC KEY BLOCK-----mFIEY+laIBMIKoZIzj0DAQcCAwQyqwvyzudbI/SasQPfwk8wTKTpfGS943PfpocqX6WNlUr79fm3YriOgBLNbWl92fiQ04jrVLuO4qFHjXRXCqY3tBtGcmVkIEJsb2dncyA8ZnJlZEBob21lLmNvbT6IkwQTEwgAOxYhBCgJu09BnND1s5jVBNE2PiMXDdkiBQJj6VogAhsjBQsJCAcCAiICBhUKCQgLAgQWAgMBAh4HAheAAAoJENE2PiMXDdkivQEBAMLDBI7lPPbNFl2bBr37qdzMD8MWcFI1x+VWonJAWmzfAQDgQX7BNz2C4ql0AtaLG+LfbW8KPTsVIVcwOBkJVTC/gw===Y0Y+-----END PGP PUBLIC KEY BLOCK-----Private key: -----BEGIN PGP PRIVATE KEY BLOCK-----lKUEY+laIBMIKoZIzj0DAQcCAwQyqwvyzudbI/SasQPfwk8wTKTpfGS943PfpocqX6WNlUr79fm3YriOgBLNbWl92fiQ04jrVLuO4qFHjXRXCqY3/gcDAr29l+/OcJdmymBkFTA6Li1y0GOLtkhWP30/F5LvyLlER9OXplzcs7j0oBJ+ZN9rRRC6W97sy4tj/s2YBr8JZTKUT+V0TWJXTpGmepbqL+G0G0ZyZWQgQmxvZ2dzIDxmcmVkQGhvbWUuY29tPoiTBBMTCAA7FiEEKAm7T0Gc0PWzmNUE0TY+IxcN2SIFAmPpWiACGyMFCwkIBwICIgIGFQoJCAsCBBYCAwECHgcCF4AACgkQ0TY+IxcN2SK9AQEAwsMEjuU89s0WXZsGvfup3MwPwxZwUjXH5VaickBabN8BAOBBfsE3PYLiqXQC1osb4t9tbwo9OxUhVzA4GQlVML+D=KamW-----END PGP PRIVATE KEY BLOCK-----
Key ID: C2E0A8F95633536EB7D05F4C37D7097A6371A8BE
Type: ecdsa-p521
Public key:
-----BEGIN PGP PUBLIC KEY BLOCK-----
mJMEY+laNxMFK4EEACMEIwQA8A0Kz1i/3baTHi1M37Qj3o60CdT6eXRyGHr72VYn
42NpsPEfbXhF+dUkGKXwonFMrSpr3dJDeoLMEPqr4GludYIAvIpPWopkPbEkyUB7
FSGQ9bpfHuqDy0L5RGE4k6dDkpEVmb7jl9CHvKYomU2doAFcmr2LQlT/NpHsiA+v
i/f/1Zq0G0ZyZWQgQmxvZ2dzIDxmcmVkQGhvbWUuY29tPojXBBMTCgA7FiEEwuCo
+VYzU2630F9MN9cJemNxqL4FAmPpWjcCGyMFCwkIBwICIgIGFQoJCAsCBBYCAwEC
HgcCF4AACgkQN9cJemNxqL7enAIJAf4WHrAwGeoRkUKwohIbplFORfad/HZDZH7G
fDxnqKeVLpHtMgSKlX5jhKdNJZwWvgy9BASSsyB+SFyLCLhBj3DoAgkBWnZryEqN
XrFGWUFr41HMLEKxXDfEUSieeTCRNkS8zODOWcemdzEc6em/1sqoySP2dmT8NRFx
BqaRoyl9MRmyp3c=
=gUWO
-----END PGP PUBLIC KEY BLOCK-----
Private key:
-----BEGIN PGP PRIVATE KEY BLOCK-----
lQEHBGPpWjcTBSuBBAAjBCMEAPANCs9Yv922kx4tTN+0I96OtAnU+nl0chh6+9lW
J+NjabDxH214RfnVJBil8KJxTK0qa93SQ3qCzBD6q+BpbnWCALyKT1qKZD2xJMlA
exUhkPW6Xx7qg8tC+URhOJOnQ5KRFZm+45fQh7ymKJlNnaABXJq9i0JU/zaR7IgP
r4v3/9Wa/gcDAg3buJmP0QDRyvMGlsik5lqJ7A5UP1HCf8ft5Ngcg2bU60t0WeEy
wTfj6uoV/2c4BBuCh++JQMBOMULHTpDo64LRLqqDz+hXEvfHiejqDek7MBLXz2ZA
m7ot6akzcGaaMT/U/2xHzJ/eXTEmY3FTdS+0G0ZyZWQgQmxvZ2dzIDxmcmVkQGhv
bWUuY29tPojXBBMTCgA7FiEEwuCo+VYzU2630F9MN9cJemNxqL4FAmPpWjcCGyMF
CwkIBwICIgIGFQoJCAsCBBYCAwECHgcCF4AACgkQN9cJemNxqL7enAIJAf4WHrAw
GeoRkUKwohIbplFORfad/HZDZH7GfDxnqKeVLpHtMgSKlX5jhKdNJZwWvgy9BASS
syB+SFyLCLhBj3DoAgkBWnZryEqNXrFGWUFr41HMLEKxXDfEUSieeTCRNkS8zODO
WcemdzEc6em/1sqoySP2dmT8NRFxBqaRoyl9MRmyp3c=
=Zubb
-----END PGP PRIVATE KEY BLOCK-----
【免责声明】市场有风险,投资需谨慎。本文不构成投资建议,用户应考虑本文中的任何意见、观点或结论是否符合其特定状况。据此投资,责任自负。