<s> import base64 <EOL> from Crypto import Random <EOL> from Crypto . Cipher import AES <EOL> class AESUtil ( object ) : <EOL> def __init__ ( self , key ) : <EOL> self . key = base64 . b64decode ( key ) <EOL> @ staticmethod <EOL> def _pad ( data ) : <EOL> length = AES . block_size - ( len ( data ) % AES . block_size ) <EOL> data += chr ( length ) * length <EOL> return data <EOL> def encrypt ( self , data ) : <EOL> iv = Random . new ( ) . read ( AES . block_size ) <EOL> cipher = AES . new ( self . key , AES . MODE_CBC , iv ) <EOL> return base64 . b64encode ( iv + cipher . encrypt ( self . _pad ( data ) ) ) <EOL> def decrypt ( self , data ) : <EOL> decoded_data = base64 . b64decode ( data ) <EOL> iv = decoded_data [ : AES . block_size ] <EOL> cipher = AES . new ( self . key , AES . MODE_CBC , iv ) <EOL> decrypted = cipher . decrypt ( decoded_data [ AES . block_size : ] ) <EOL> return decrypted [ : - ord ( decrypted [ len ( decrypted ) - <NUM_LIT:1> : ] ) ] </s>
