def encrypt_file(filename, keyfile, crypted_filename=None, ascii_armour=False): if not crypted_filename: crypted_filename = filename + ".aes256" plaintext = load(filename) iv = block.generate_nonce() key = load(keyfile) ciphertext = block.encrypt(key, plaintext, iv, ascii_armour) print "[+] encrypted %s to %s..." % (filename, crypted_filename) dump(crypted_filename, ciphertext) print "[+] file written..."
def test_random_key(): key = block.generate_aes_key() message = 'This is a sample message. 1234567890ABCDEF' print '\t[+] test message: \'%s\'' % message assert( len(key) == 32 ) iv = block.generate_nonce() ct = block.encrypt( key, message, iv ) pt = block.decrypt( key, ct, iv ) assert( pt == message ) print '\t[+] successfully decrypted!'
def test_armoured(): key = block.generate_aes_key() message = 'This is a sample message. 0123456789ABCDEF' print '\t[+] test message: \'%s\'' % message assert( len(key) == 32 ) iv = block.generate_nonce() ct = block.encrypt( key, message, iv, armour = True ) print_ct = ct.replace('\n', '\n\t').rstrip() print '\t[+] ciphertext: \n\t%s' % print_ct pt = block.decrypt( key, ct ) assert( pt == message ) print '\t[+] successfully decrypted!'