使用 PyCrypto RSA
import base64
from Crypto.PublicKey import RSA
key = RSA.importKey(open('./keyBR.pub', 'r').read())
privkey = RSA.importKey(open('./privkeyBR.pem', 'r').read())
>>> message = "This is the story"
>>> ciphertext = key.encrypt( message, None )
>>> print ciphertext
("\xd9\x97o\x85#\xc8\xba\x14\xc9\xa4h\xacg\xc8\xc7\xb3\xbfA\xf1\x8e\x8aI\xe72IT\x03\x1a\xb7\x19\xd4\xb0\x9f\x9a\xde\x13-m\x9dw\x9d\\\x8f\x9fG\xb8(\x91\xa3\xcd\xad\xf6\xea(\x16\xd5]\xeb\x96\xc5\xe3\xecy\x9b\xf9o\x0b\\P3b\xac\xcf\xcf#\xe5\x9e\x07\xe0&\x1f8\x145!\xc8\xc9\xe0x\x7f\xa1\xbf\x03\xda\xa8z]\xa3\xff\xa7\xf0\xa7\t\xef\x80An\xd8i\xd9\xb8_1\xb7\x02\x1e\xa3\xb4z\x99c\x1d\x85\xef#b\xe8a\x18\xd3\xe09\x7f\xb6\x91!\x0b\x06\x07\xb0\xd3\xa3\x7f\xc5\x97\xa1\x90\x94\xa7M\xd8\xf2(\xe3\xe3\xc2\x1es\xba\xae\x0c\xb7\xa6\xe1\xd2\xb03\xc1\xcaU\xca@\xd1\x81\xde@\xa0\t\xf1<c\x9e\x8a\x8b\x88Lj\x16 lc\xae<\xbf\x16R\xe8\x04}\xcd\x7f\x0bZA\xd9y\x14\x03\xb7Hg\xac\xf4\xa5\xce\xe0\xa2\x8b\xdai\x03\xbb5\x99XS\xfe/\xc7I\xd3D\x81'xZ\xed\xce\t,E\xfc\x90\x1a_\xb3\xa7s\x0coA&1/\x06 ",)
privkey.decrypt(ciphertext[0]) '这就是故事'
密文[0]的格式是什么?我以为它是 utf-8,但当我尝试时它失败了。
我正在使用 Debian 64bits,python 2.7,以防万一。