-
Notifications
You must be signed in to change notification settings - Fork 520
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
910 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
.. _rsa_oaep: | ||
|
||
PKCS#1 OAEP (RSA) | ||
================= | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,59 @@ | ||
RSA | ||
=== | ||
|
||
RSA_ is the most widespread and used public key algorithm. Its security is | ||
RSA_ is one of the most widespread and public key algorithms. Its security is | ||
based on the difficulty of factoring large integers. The algorithm has | ||
withstood attacks for more than 30 years, and it is therefore considered | ||
reasonably secure for new designs. | ||
reasonably secure. | ||
|
||
The algorithm can be used for both confidentiality (encryption) and | ||
authentication (digital signature). It is worth noting that signing and | ||
However, for new designs, it is recommended to use :doc:`ECC <ecc>`, | ||
because keys are smaller and private key operations are faster. | ||
|
||
The RSA algorithm can be used for both confidentiality (encryption) and | ||
authentication (digital signature). Signing and | ||
decryption are significantly slower than verification and encryption. | ||
|
||
The cryptographic strength is primarily linked to the length of the RSA modulus *n*. | ||
In 2017, a sufficient length is deemed to be 2048 bits. For more information, | ||
see the most recent ECRYPT_ report. | ||
|
||
Both RSA ciphertexts and RSA signatures are as large as the RSA modulus *n* (256 | ||
bytes if *n* is 2048 bit long). | ||
|
||
The module :mod:`Crypto.PublicKey.RSA` provides facilities for generating new RSA keys, | ||
reconstructing them from known components, exporting them, and importing them. | ||
In 2023, a sufficient length is deemed to be 3072 bits. For more information, | ||
see the most recent NIST_ report. | ||
Both RSA ciphertexts and RSA signatures are as large as the RSA modulus *n* (384 | ||
bytes if *n* is 3072 bit long). | ||
|
||
As an example, this is how you generate a new RSA key pair, save it in a file | ||
called ``mykey.pem``, and then read it back:: | ||
With this module you can generate new RSA keys:: | ||
|
||
>>> from Crypto.PublicKey import RSA | ||
>>> | ||
>>> key = RSA.generate(2048) | ||
>>> f = open('mykey.pem','wb') | ||
>>> f.write(key.export_key('PEM')) | ||
>>> f.close() | ||
... | ||
>>> f = open('mykey.pem','r') | ||
>>> key = RSA.import_key(f.read()) | ||
>>> mykey = RSA.generate(3072) | ||
|
||
export an RSA private key and protect it with a password, so that it is | ||
resistant to brute force attacks:: | ||
|
||
>>> pwd = b'secret' | ||
>>> with open("myprivatekey.pem", "wb") as f: | ||
>>> data = mykey.export_key(passphrase=pwd, | ||
pkcs=8, | ||
protection='PBKDF2WithHMAC-SHA512AndAES256-CBC', | ||
prot_params={'iteration_count':131072}) | ||
>>> f.write(data) | ||
|
||
and reimport it later:: | ||
|
||
>>> pwd = b'secret' | ||
>>> with open("myprivatekey.pem", "rb") as f: | ||
>>> data = f.read() | ||
>>> mykey = RSA.import_key(data, pwd) | ||
|
||
You can also export the public key, which is not sensitive:: | ||
|
||
>>> with open("mypublickey.pem", "wb") as f: | ||
>>> data = mykey.public_key().export_key() | ||
|
||
For signing data with RSA, use a higher level module such as :ref:`rsa_pss`. | ||
|
||
For encrypting data with RSA, use :ref:`rsa_oaep`. | ||
|
||
.. _RSA: http://en.wikipedia.org/wiki/RSA_%28algorithm%29 | ||
.. _ECRYPT: http://www.ecrypt.eu.org/ecrypt2/documents/D.SPA.20.pdf | ||
.. _NIST: https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r5.pdf | ||
|
||
.. automodule:: Crypto.PublicKey.RSA | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
.. _rsa_pss: | ||
|
||
PKCS#1 PSS (RSA) | ||
================ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.