Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What type of padding does python use for RSA module?

I'm new to encryption with Python and am wondering which padding is the default one for its RSA module?

I get the key and decrypt the data by:

import rsa

(pub, priv) = rsa.newkeys(512)
# receive the encrypted data here
data = rsa.decrypt(encrypt_data, priv)

And as far as I am concerned, the padding methods include: RSA_PKCS1_PADDING, RSA_PKCS1_OAEP_PADDING, RSA_SSLV23_PADDING, RSA_NO_PADDING.

like image 211
zzy Avatar asked Aug 09 '26 22:08

zzy


1 Answers

The rsa module (currently v3.4) supports only PKCS#1 v1.5 padding for encryption (randomized type 2 padding) and signing.

In rsa/__init__.py you can see that rsa.encrypt() is actually rsa.pkcs1.encrypt() which internally uses rsa.pkcs1._pad_for_encryption() which is an implementation of the previously mentioned PKCS#1 v1.5 padding.

Please note that nowadays (ref), this padding should not be used anymore. OAEP is recommended for encryption and PSS for signing, both from PKCS#1 v2.0. PyCrypto supports OAEP/PSS and PKCS#1 v1.5 paddings.

like image 60
Artjom B. Avatar answered Aug 11 '26 11:08

Artjom B.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!