网址:http://www.bubuko.com/infodetail-2349299.html
示例:
import base64 import rsa def strkey(strk): b_str = base64.b64decode(strk) if len(b_str) < 162: return False hex_str = ‘‘ # 按位转换成16进制 for x in b_str: h = hex(ord(x))[2:] h = h.rjust(2, ‘0‘) hex_str += h # 找到模数和指数的开头结束位置 m_start = 29 * 2 e_start = 159 * 2 m_len = 128 * 2 e_len = 3 * 2 modulus = hex_str[m_start:m_start + m_len] exponent = hex_str[e_start:e_start + e_len] return modulus, exponent if __name__ == ‘__main__‘: pub_str = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDPg0O4rPQJL1O+jqJ4rBjFVNRAuDmBSoii9pYfPQBaescCVY0irkWWoLyfTT65TjvnPpOx+IfNzBTlB13qCEFm7algREoeUHjFgFNHiXJ2LK/R0+VWgXe5+EDFfbrFCPnmLKG3OcKDGQszP0VOf6VVTM1t56CpgaRMm1/+Tzd2TQIDAQAB" modulus, exponent = strkey(pub_str) modulus = int(modulus, 16) exponent = int(exponent, 16) pub_key = rsa.PublicKey(modulus, exponent) print pub_key