在python中通过公钥编码字符串的最佳方法是什么 [英] What is the best way to encode string by public-key in python

查看:61
本文介绍了在python中通过公钥编码字符串的最佳方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法通过公钥对字符串进行编码?

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

我找到了两个包,pycrypto 和 m2crypto.但我找不到如何使用它们.

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

推荐答案

使用公钥对字符串进行编码:

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)

这篇关于在python中通过公钥编码字符串的最佳方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆