CRYPTO EXAMPLE WITH PYTHON RSA MODULE
In this article we will talk about how you can encrypt using the RSA module in Python. It’s very simple to use. But to do this, the RSA module needs to be installed first. To do this, just type the following command.
Crypto with Python
1 | sudo pip install rsa |
After installing the module is very simple to use. Let’s look at this example.
1 2 3 4 5 6 7 8 9 10 11 12 13 | import rsa (encryption key,encryption key) = RSA.newkeys (512)) message = 'python classes' password = RSA.encrypt(message,decryption key) Solution = RSA.decrypt(encryption,the decryption key) print encryption Print decryption ##Sample output 4 D C D*) D D D D D D A D D G H H H P H H P E 7l ƚm:n □ of □ of □ > Python Lessons |
- 1.line : RSA module imported.
- 3.line : the keys were generated for encryption with RSA module. Specifies the number of 512 bits here.
- 7.line : encryption is done by encrypt method. The key is used when encryption is made.
- 8.line : decrypt medou decrypted text. The key Generated when decrypting is used.
If we want, we can use the Cryptography algorithms we know. For example, let’s encrypt a text with sha512. Therefore
1 2 3 4 5 6 7 8 9 10 | import rsa (encryptionkey,encryptionkey) = RSA.newkeys (752)) message = 'python classes' password = RSA.sign(message,password,'SHA-512') print encryption #Sample Output □ of □ of □ e�����/����Qb!n7 d _|7VT d / □ of □ q □ of □ OF □ of i Km⢐collected ȁq ʝ R D D D D □ of □ OF □ of 3= □ of □ of d ŧ 16E�� ��6 D E D] D l"D~D R=D |
We use the sign method for this method. To be able to encrypt with SHA-512, the bit length must be at least 752.
much more detailed information about the RSA module http://stuvel.eu/rsa you can find it at http://stuvel.eu/rsa