What is the best way to encode string by public-key in python

杀马特。学长 韩版系。学妹 提交于 2019-12-12 02:09:38

问题


Is there any way to encode string by public-key?

I found two packages, pycrypto and m2crypto. But I can not find how to use them.


回答1:


To encode a string using public key:

#!/usr/bin/env python 
from M2Crypto import RSA, X509

x509 = X509.load_cert("recipient_cert.pem")
rsa = x509.get_pubkey().get_rsa()
print rsa.public_encrypt("your string to encrypt", RSA.pkcs1_oaep_padding)


来源:https://stackoverflow.com/questions/7563732/what-is-the-best-way-to-encode-string-by-public-key-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!