
Jbulfr2n+Ez7MrfZwlTwPb0BiOS45AxHtkwb0lcoNLk2/8PamVNlfvi+6AxJwsEp MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCaEUhbzLlWlBCoSPsa/fKoGxfB Run the above code example: RSA Decryption Finally, decrypt the message using using RSA-OAEP with the RSA private key: decryptor = PKCS1_OAEP.new(keyPair) Print( "Encrypted:", binascii.hexlify(encrypted)) Next, encrypt the message using RSA-OAEP encryption scheme (RSA with PKCS#1 OAEP padding) with the RSA public key: msg = b'A message for encryption'

Run the above code example: use short key length to keep the sample input short, but in a real world scenario it is recommended to use 3072-bit or 4096-bit keys.


First, generate the RSA keys (1024-bit) and print them on the console (as hex numbers and in the PKCS#8 PEM ASN.1 format): from Crypto.PublicKey import RSA The below code will generate random RSA key-pair, will encrypt a short message and will decrypt it back to its original form, using the RSA-OAEP padding scheme.įirst, install the pycryptodome package, which is a powerful Python library of low-level cryptographic primitives (hashes, MAC codes, key-derivation, symmetric and asymmetric ciphers, digital signatures): pip install pycryptodome Now let's demonstrate how the RSA algorithms works by a simple example in Python. RSA Encryption / Decryption - Examples in Python
