Avatar

Blogging tips

Avatar

Python, Django and Flask

Avatar

Latest tech posts

Monday, December 23, 2019

Encrypt and decrypt audio files using AES 256 algorithm in python

Encryption is the process of translating plain text data (plaintext) into something that appears to be random and meaningless (ciphertext). Decryption is the process of converting ciphertext back to plaintext. To encrypt more than a small amount of data, symmetric encryption is used.



AES 256 algorithm

AES (acronym of Advanced Encryption Standard) is a symmetric encryption algorithm. The algorithm was developed by two Belgian cryptographers Joan Daemen and Vincent Rijmen. AES was designed to be efficient in both hardware and software and supports a block length of 128 bits and key lengths of 128, 192, and 256 bits.

Pycrypto

In python, AES algorithm can be implemented by using a python library called pycrypto.

pip install pycrypto

The algorithm requires an AES key of 32 bytes and an IV(initialization vector ) of 16 bytes.
The same key and IV should be used at the decryption end.

The code for AES 256 in python to encrypt audio files is,



Concept


  1. Generate key and IV using random functions.
  2. open the file and read it. This will return bytes as the algorithm requires the data to be in the form of bytes.
  3. Encrypt it using the encrypt function of the pycrypto library.
  4. Write the encrypted bytes into a file. (optional)
  5. Take the encrypted bytes data and pass it to the decrypt function
  6. The resulting decrypted bytes data can be written to another file as a decrypted audio file.
#python #encryption #decryption


No comments:

Post a Comment