python_rsa加密解密
Posted Alive
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python_rsa加密解密相关的知识,希望对你有一定的参考价值。
使用python进行rsa加密与加密,包括公钥加密私钥解密,私钥加密公钥解密。(需要安装M2Crypto库)。
#!/usr/bin/env python #encoding=utf-8 ‘‘‘ 测试rsa加密解密 ‘‘‘ from M2Crypto import RSA msg = ‘aaaa-aaaa‘ rsa_pub = RSA.load_pub_key(‘rsa_pub.pem‘) rsa_pri = RSA.load_key(‘rsa_pri.pem‘) print ‘*************************************************************‘ print ‘公钥加密,私钥解密‘ ctxt = rsa_pub.public_encrypt(msg, RSA.pkcs1_padding) ctxt64 = ctxt.encode(‘base64‘) print (‘密文:%s‘% ctxt64) rsa_pri = RSA.load_key(‘rsa_pri.pem‘) txt = rsa_pri.private_decrypt(ctxt, RSA.pkcs1_padding) print(‘明文:%s‘% txt) print ‘*************************************************************‘ print ‘私钥加密,公钥解密‘ ctxt_pri = rsa_pri.private_encrypt(msg, RSA.pkcs1_padding) ctxt64_pri = ctxt.encode(‘base64‘) print (‘密文:%s‘% ctxt64_pri) txt_pri = rsa_pub.public_decrypt(ctxt_pri, RSA.pkcs1_padding) print(‘明文:%s‘% txt_pri)
库的安装说明
M2Crypto库的下载地址:
https://github.com/martinpaljak/M2Crypto
或者:https://pypi.python.org/pypi/M2Crypto
依赖的库:openssh-devel gcc swig (这3个库在centos上可以直接使用yum安装)
原文链接:
https://www.jb51.net/article/79596.htm
以上是关于python_rsa加密解密的主要内容,如果未能解决你的问题,请参考以下文章
Android 高级UI解密 :PathMeasure截取片段 与 切线(新思路实现轨迹变换)
Android 高级UI解密 :PathMeasure截取片段 与 切线(新思路实现轨迹变换)