English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Installation and Usage Method of Python Crypto Module

Preface

Initially, I wanted to try installing Python on Windows3.6, although Python was installed successfully, when installing the Cryto module using pip3 Installing pycrypto always results in errors. After struggling for a while, I finally decided to do it on Linux.

The following process is limited to Linux systems:

Crypto is not a built-in module and needs to be downloaded.http://www.voidspace.org.uk/python/modules.shtml#pycrypto

After I downloaded it, I found that I downloaded crypto instead of Crypto (just a difference in the case of the first letter)

And crypto.Cipher can't run, it reports an error, and finally at:https://stackoverflow.com/questions/31485110/no-module-named-crypto-cipher/31485157 To find the answer, you need to find Python in the directory and rename Python27\Lib\site-packages under the crypto file rename, that's right, just rename it to Crypto. Then it can be used...

(Because I downloaded the uninstall version above, so I didn't install VS)2008I have used pip, and I can't download Crypto. Installing these modules on Windows is really a pain. If my computer were better, I would set up a dual system...Sorry for going off-topic...

0x00 Install python

apt-get install python3.6 

0x01 Install pip3

1.Firstly install setuptool

wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26 
tar -zxvf setuptools-19.6.tar.gz 
cd setuptools-19.6.tar.gz 
python3 setup.py build 
python3 setup.py install 

2.Then directly install pip to solve the problem

wget --no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb 
tar -zxvf pip-8.0.2.tar.gz 
cd pip-8.0.2 
python3 setup.py build 
python3 setup.py install 

0x02 install crypto

apt-get install python3-dev 
pip3 install Crypto 
pip3 install --upgrade pycrypt 

The following mainly introduces the AES algorithm of Crypto.Cipher.

The code is as follows:

from Crypto.Cipher import AES 
import base64 
secret = "12345678912345678912345678912345"   # Input by the user16bit or24bit or32bit length of the initial password string 
cipher = AES.new(secret)            # Through AES to process the initial password string and return the cipher object 
s = cipher.encrypt("1234567891234567")     #输入需要加密的字符串,注意字符串长度要是16multiple.16,32,48.. 
print s                     # Output the encrypted string 
print base64.b64encode(s)            # Output the base64Encoding. 
print cipher.decrypt(s)             # Decrypt 

This is for the beginners (me) to understand, and general processing methods can be referred to at https://www.oldtoolbag.com/article/114364.htm

As to why the encrypted string has to be encoded again with base64Encoding, I think the processing of the string is based on binary, while base64The principle is to every6Add two zeros to the front of the binary number, so that the ascii encoding of the processed string is all visible (at least not those question mark characters...), test it with the charset module, and find it is also as I said.

The DES algorithm is used in the same way as AES, but you must pay attention to the initial password string must be8While other places can replace AES with DES (Python is still very convenient if you don't remember to configure the environment...)

This Crypto module also has other encryption algorithms such as hash algorithms. If there are great masters or friends who dig this module, please leave a message below. By the way, also teach me how to use it, thank you all!

That's all for this article. I hope it will be helpful to everyone's learning, and I also hope everyone will support the Yelling Tutorial more.

Declaration: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been edited by humans, and does not assume relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (Please replace # with @ when sending an email to report abuse, and provide relevant evidence. Once verified, this site will immediately delete the infringing content.)

You May Also Like