Python des and 3DES plus decryption

Source: Internet
Author: User
Tags decrypt

1. Encryption:

pydes.des (key, [mode], [IV], [pad], [Padmode]) Pydes.triple_des (key, [mode], [IV], [pad], [padmode]) key-Bytes containing the encryption key. 8 bytes forDES, 16or24bytes forTriple DesmodeOptional argument forencryption type, can is either PYDES.ECB (Electronic Code book)orPYDES.CBC (Cypher Block Chaining) IV-Optional Initial Value bytes, must be suppliedifusing CBC mode. Length must be8Bytes.pad-Optional argument, set the pad character (Pad_normal) to use during all encrypt/decrpt Operations done with this Instance.padmode-Optional argument, set the padding mode (pad_normalorPAD_PKCS5) to use during all encrypt/DECRPT operations done with this instance.

Instance:

Example------- fromPydesImport*Data="Please encrypt my data"k= des ("Descrypt"Cbc"\0\0\0\0\0\0\0\0", Pad=none, padmode=pad_pkcs5)#For Python3, you'll need to use bytes, i.e.:#data = B "Please encrypt my data"#k = des (b "descrypt", CBC, B "\0\0\0\0\0\0\0\0", Pad=none, PADMODE=PAD_PKCS5)D =k.encrypt (data)Print "Encrypted:%r"%DPrint "decrypted:%r"%K.decrypt (d)assertK.decrypt (d, padmode=pad_pkcs5) = = Data

Python des and 3DES plus decryption

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.