sybrenstuvel/python-rsa

Public key decryption problem

git-ruoshui opened this issue · 4 comments

public_key = PublicKey.load_pkcs1_openssl_pem(RSA_PUBLIC_KEY.encode())
c_text = transform.bytes2int(ciphertext)
decrypted = core.decrypt_int(c_text, public_key.e, public_key.n)
bytes_text = transform.int2bytes(decrypted)
print(str(bytes_text, encoding="utf-8", errors='ignore'))

'''

�~�&&.�E�'OlP�g,.rԸs$#q%uWst9Q��*5)(j®ڐC�ʦà^vaN^s{3st+��#W{,1ڂ<頎c1
���_�X�v�
'''

The return value is always garbled(utf-8,gbk,...). same public key ,java can do it. why?

Java is a language, so I don't know what you mean with "java can do it".

You're trying to use plain RSA decryption, but you explain nothing about how the ciphertext got encrypted. There is not enough information to help.

I tried to use the rsa library for public key decryption, the same ciphertext and public key, rsa this library using the above method can not solve the original text (garbled), but I solved it correctly with Java. Note: ciphertext is encrypted using Java using private key.

There are many different ways in which to use RSA to encrypt something. See https://stuvel.eu/python-rsa-doc/compatibility.html for more info.

I'll close this thread. If you want to discuss further, please feel free to reopen it.