I have server written in python
and client in C
. Their job is to send a secret message from server to client which is encrypted with RSA private key
. I am using openssl/rsa.h
library, that is I initialize a rsa
object with a private key and encrypte a message with RSA_public_encrypt(length_of_message, "Secret Message", to, rsa, RSA_PKCS1_PADDING)
. Then I send this encrypted message to python
server and try to decrypt it with same private key using from Crypto.PublicKey import RSA
library. Problem is that it does not decrypt it properly. It always outputs 128-bit length message where the secret message is randomly placed in it (e.g. '\x23\xa3x\43...Secret Message\xef\x4a')
, where it should normally return just Secret Message
.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- Multiple sockets for clients to connect to
- How to get the background from multiple images by
- Evil ctypes hack in python
Is it possible to create a same pair of RSA key in Python and C . please find the code below and let me know if any modification needed to get it worked.
Code in python
Code in C
The problem was about the padding. Python's rsa module decrypts result with
PKCS1
padding and does not removes padding. With the function below which I have taken from here problem was solved: