Python AES encryption and decryption Pycryptodome

Source: Internet
Author: User

Environmental pyhton3.6

Pip is upgraded to more than 10.0, or it may not be possible to install.

Bo Master in order to decode AES for 1 days, Ann a variety of bags, but walked a lot of pits, here to provide you with a simple method

First on the command line (recommended) pip install Crypto

You will find that the package name installed is lowercase. (crypto)

The path to the package is under your python/lib/site_packages.

You must first change to uppercase (Crypto)

However, importing from Crypto.cipher import AES is an error because you also need to install dependent packages.

Command line pip Install Pycrypto ... You find it seems to have an error, it is because this bag has not been maintained, do not worry that everything is in control!!!

After reviewing a large amount of information, we found that after this package, a new package----pycryptodome--------


Pip install Pycrypto Ann on the line, congratulations on your success.

ImportBase64 fromCrypto.cipherImportAES#STR is not a multiple of 16 then it is a multiple of 16.defadd_to_16 (value): whileLen (value)% 16! =0:value+=' /'    returnStr.encode (value)#back to bytesKey='123456'  #Passwordtext='abc123def456'  #Text to encryptAES= Aes.new (Add_to_16 (key), AES. MODE_ECB)#Initialize the encryption deviceEncrypted_text= str (base64.encodebytes (Aes.encrypt (add_to_16 (text))), encoding='Utf-8'). Replace ('\ n',"')#perform encryption and transcode back to bytesPrint(Encrypted_text)

Attach the test code.

Python AES encryption and decryption Pycryptodome

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.