要用到chilkat库.
下载地址
import sys
import chilkat
cert = chilkat.CkCert()
success = cert.LoadFromFile("/Users/xxxxx/test.cer")
if (success != True):
print(cert.lastErrorText())
sys.exit()
# pubKey is a CkPublicKey
pubKey = cert.ExportPublicKey()
csstring = chilkat.CkString()
result = pubKey.getPem(True)
print(result)
得到的结果是这种格式,可以直接拿来用:
-----BEGIN RSA PUBLIC KEY-----
MIGJAoGBAKFwh3fgFnhyNNvd53K8a1h+53WqJuEs8qUt0RqGkF9YELm40d/VPlPt
7m6LsXIQQx8GaROGfQl4g57sfv2D9edLQYiv+ppoQ+uWYzvnUA8/PTbMnjyXQlC0
dEGNPCzcBZ61ZV9+M2xLPAUiiIxlKSRuNW3lvOWDKLkL6pdrFhXfAgMBAAE=
-----END RSA PUBLIC KEY-----
网友评论