I am using the RSA python package to encrypt a message and try to pass it to a PHP site to decrypt. See below:

message = rsa.encrypt('abc', pubkey)
print message
print type(message)

What I get is some encrypted text

q??$$??kK?Y??p?[e?[??f???x??s!?s?>?z?*y?p?????????分?
?   ???({u????NH?B???N?%?@5|?~?????\U?.??r?Y?q
<type 'str'>

What's the best way to pass it to other languages to decrypt?

有帮助吗?

解决方案

That's not a text, it's a binary data. As you are using python2 it doesn't fully distinguish bytes from str so you should care about this.

The other side should get this bytes exactly as rsa outputs them so you can just write them into your connection or file (presuming you are talking binary to them).

其他提示

For web you can base64 encode the data. It's a common and good way to encode binary data.

>>> import base64
>>> base64.b64encode(b"data")
'ZGF0YQ=='
>>> base64.b64decode(base64.b64encode(b"data"))
'data'

By the way you are not suppose to use RSA that way. It's highly insecure to use raw RSA. You must use a probabilistic encryption scheme with proper padding, e.g. RSAES-OAEP. PKCS#1 defines such scheme for encryption and signatures.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top