Encrypts data with the provided key. The returned byte array is as follow: :==============:==================================================: : IV (16bytes) : Encrypted (data + PKCS7 padding information) : :==============:==================================================:
(clearText, key)
| 47 | |
| 48 | #------------------------------------------------------------------------ |
| 49 | def aesEncrypt(clearText, key): |
| 50 | """Encrypts data with the provided key. |
| 51 | The returned byte array is as follow: |
| 52 | :==============:==================================================: |
| 53 | : IV (16bytes) : Encrypted (data + PKCS7 padding information) : |
| 54 | :==============:==================================================: |
| 55 | """ |
| 56 | |
| 57 | # Generate a crypto secure random Initialization Vector |
| 58 | iv = urandom(AES.block_size) |
| 59 | |
| 60 | # Perform PKCS7 padding so that clearText is a multiple of the block size |
| 61 | clearText = pad(clearText) |
| 62 | |
| 63 | cipher = AES.new(key, AES.MODE_CBC, iv) |
| 64 | return iv + cipher.encrypt(bytes(clearText)) |
| 65 | |
| 66 | #====================================================================================================== |
| 67 | # OUTPUT FORMAT FUNCTIONS |
no test coverage detected