python extract public key from pem format publi key.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from Crypto.PublicKey import RSA
def main(argv):
finput = open(argv[1], 'r')
rsa=RSA.importKey(finput) # there could import public key.
output=argv[2]
with open(output, 'wb') as f:
f.write(rsa.exportKey('DER'))
if __name__ == '__main__':
sys.exit(main(sys.argv))
Now, openssl command line only can extract public key from private key.
So ther I provide scripts extract der format public key from pem public key.
python extract_pub_key.py test_pub.pem test_pub.der

浙公网安备 33010602011771号