python rsa加密
原文地址:https://www.programcreek.com/python/example/83019/rsa.PublicKey
| def get_pwd_rsa(self,pwd,servertime,nonce): | |
| “”” | |
| 获取rsa2加密密码,使用https://pypi.python.org/pypi/rsa/3.1.1中的RSA模块,可以访问以下文档: | |
| http://stuvel.eu/files/python-rsa-doc/index.html | |
| “”” | |
| # n,RSA公钥的n参数,由WEIBO.COM发布 | |
| #在这里硬编码的,但你也可以找到它的值从上述预登录状态返回 | |
| weibo_rsa_n = ' EB2A38568661887FA180BDDB5CABD5F21C7BFD59C090CB2D245A87AC253062882729293E5506350508E7F9AA3BB77F4333231490F915F6D63C55FE2F08A49B353F444AD3993CACC02DB784ABBB8E42A9B1BBFFFB38BE18D78E87A0E41B9B8F73A928EE0CCEE1F6739884B9777E4FE9E88A1BBE495927AC4A799B3181D6442443 ' | |
| # e,RSA公钥的exponent参数,WEIBO使用0x10001,在Decimal中为65537 | |
| weibo_rsa_e = 65537 | |
| message = str(servertime)+ ' \ t ' + str(nonce)+ ' \ n ' + str(pwd) | |
| #使用上面的n和e构造WEIBO RSA Publickey,注意n是十六进制字符串 | |
| key = rsa.PublicKey(int(weibo_rsa_n,16),weibo_rsa_e) | |
| #获取加密密码 | |
| encropy_pwd = rsa.encrypt(消息,密钥) | |
| # TRUN回加密的密码的二进制文件的十六进制字符串 | |
| return binascii.b2a_hex(encropy_pwd) |

浙公网安备 33010602011771号