Python RSA Encryption And Decryption Example
The cryptographic technique known as Rivest-Shamir-Adleman, or RSA, is used for certain security services or goals. It allows for public-key encryption and is frequently used to protect sensitive data, especially when it's being transferred over an unreliable network like the HTTP. Whereas a private key is confidential and needs to be kept to yourself, a public key is shared with others. The following illustration highlights how asymmetric cryptography works: Example: RSA Encryption and Decryption with RSA-OAEP Padding from Crypto.PublicKey import RSA from Crypto.Cipher import PKCS1_OAEP import base64 # 2048 is the number of bits for RSA keys = RSA.generate( 2048 ) publicKey = keys.publickey() publicKeyPEM = publicKey.exportKey() print( "\n" ,publicKeyPEM.decode( 'ascii' )) privateKeyPEM = keys.exportKey() print( "\n" ,privateKeyPEM.decode( 'ascii' )) # Your secret text secretMessage = 'This is your secret' #encrypt the messag