0% found this document useful (0 votes)
36 views1 page

From Import Import Import

This 3 sentence summary provides the key details about the Python code: The code shows how to encrypt and decrypt a string using AES encryption in Python with a randomly generated secret key, it pads the string to be a multiple of the 32 byte block size and uses base64 encoding, and it includes functions to encrypt/encode and decrypt/decode a string.

Uploaded by

m4r10
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views1 page

From Import Import Import

This 3 sentence summary provides the key details about the Python code: The code shows how to encrypt and decrypt a string using AES encryption in Python with a randomly generated secret key, it pads the string to be a multiple of the 32 byte block size and uses base64 encoding, and it includes functions to encrypt/encode and decrypt/decode a string.

Uploaded by

m4r10
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

/home/mario/lixo/python/aes-pycrypto.py Page 1 of 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 #!/usr/bin/env python from Crypto.

Cipher import AES import base64 import os

Thu 19 Dec 2013 01:38:14 PM BRST

# the block size for the cipher object; must be 16, 24, or 32 for AES BLOCK_SIZE = 32 # the character used for padding--with a block cipher such as AES, the value # you encrypt must be a multiple of BLOCK_SIZE in length. This character is # used to ensure that your value is always a multiple of BLOCK_SIZE PADDING = '{' # one-liner to sufficiently pad the text to be encrypted pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING # one-liners to encrypt/encode and decrypt/decode a string # encrypt with AES, encode with base64 EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s))) DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(PADDING) # generate a random secret key secret = os.urandom(BLOCK_SIZE) # create a cipher object using the random secret cipher = AES.new(secret) # encode a string encoded = EncodeAES(cipher, 'password') print ('Encrypted string: %s' % encoded) # decode the encoded string decoded = DecodeAES(cipher, encoded) print ('Decrypted string: '+str(decoded))

- 1 -

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy