Exemple #1
0
    def get_passfile(passphrase, passfile='.gmailsend', relativepath=True):
        if (relativepath):
            passfile = os.path.dirname(__file__) + '/' + passfile

        with open(passfile, 'r') as fin:
            host = fin.readline()
            port = fin.readline()
            account = fin.readline()
            password = fin.readline()

        cipher = AESCipher(generate_secret_key(passphrase))
        host = cipher.decrypt(host)
        port = int(cipher.decrypt(port))
        account = cipher.decrypt(account)
        password = cipher.decrypt(password)
        return host, port, account, password
Exemple #2
0
def aes_decryption():
    key = generate_secret_key(password)
    cipher = AESCipher(key)
    local_file_reader = open(tmp_data_encrypted, 'r')
    local_file_data = local_file_reader.read()
    local_file_reader.close()
    local_file_writer = open(tmp_data_plain, 'w')
    local_file_writer.write(cipher.decrypt(local_file_data))
    local_file_writer.close()
    print_success('the retrieved hidden data from "' + video_container + '" is located at "' + tmp_data_plain + '", this data will make sense as long as the password was correct')
    exit(0)
    def decrypts(self):

        ciphertext = self.t1.get("1.0", tk.END)
        ciphertext = ciphertext.strip()
        pass_phrase = self.tkey.get()
        secret_key = generate_secret_key(pass_phrase)
        print(secret_key)
        cipher = AESCipher(secret_key)
        message = cipher.decrypt(ciphertext)

        self.t2.delete('1.0', tk.END)
        self.t2.insert("1.0", message)
Exemple #4
0
def connected(tag):
    print >> sys.stderr, 'tag touched'
    obj = AESCipher(tagops.read_password(tag))
    #ciphertext = obj.encrypt('secret data')
    #b64ciphertext = base64.b64encode(ciphertext)
    #print(b64ciphertext)
    with open('secret.base64', 'r') as f:
        print(obj.decrypt(base64.b64decode(f.readline())))


#    sys.exit(0)
    return True
Exemple #5
0
class Passworder():
    def __init__(self):

        # TODO:パスフレーズは環境変数から設定するようにする
        pass_phrase = "hogefuga"
        secret_key = generate_secret_key(pass_phrase)

        # generate cipher
        self.cipher = AESCipher(secret_key)

    def _encrypt(self, raw_text):
        return self.cipher.encrypt(raw_text)

    def _decrypt(self, encrypt_text):
        return self.cipher.decrypt(encrypt_text)
Exemple #6
0
def execute_encryption(is_encryption, input_word):
    pass_phrase = os.environ.get('ENCRYPT_PASS_PHARSE')
    secret_key = generate_secret_key(pass_phrase)

    # Generate cipher
    cipher = AESCipher(secret_key)

    executed_word = ''
    if is_encryption:
        # Encryption
        executed_word = cipher.encrypt(input_word)
    else:
        # Dencryption
        if ' ' in input_word:
            input_word = input_word.replace(' ', '+')
        executed_word = cipher.decrypt(input_word)

    return executed_word
class TestAESCipher(unittest.TestCase):
    def setUp(self):
        pass_phrase = self._choice_randome_string()
        self.secret_key = generate_secret_key(pass_phrase)
        self.cipher = AESCipher(self.secret_key)

    def _choice_randome_string(self):
        return ''.join([random.choice(string.ascii_letters + string.digits)])

    def test_encrypt(self):
        text = self._choice_randome_string()
        encrypt_text = self.cipher.encrypt(text)
        self.assertNotEqual(text, encrypt_text)

    def test_decrypt(self):
        text = self._choice_randome_string()

        encrypt_text = self.cipher.encrypt(text)
        self.assertNotEqual(text, encrypt_text)

        decrypt_text = self.cipher.decrypt(encrypt_text)
        self.assertNotEqual(encrypt_text, decrypt_text)
        self.assertEqual(text, decrypt_text)
import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../')

from simple_aes_cipher import AESCipher, generate_secret_key

pass_phrase = "hogefuga"
secret_key = generate_secret_key(pass_phrase)

# generate cipher
cipher = AESCipher(secret_key)

raw_text = "abcdefg"
encrypt_text = cipher.encrypt(raw_text)
assert raw_text != encrypt_text

decrypt_text = cipher.decrypt(encrypt_text)
assert encrypt_text != decrypt_text
assert decrypt_text == raw_text


f = open('README.rst')
doc = f.read()
f.close()

print(doc)
Exemple #9
0
from simple_aes_cipher import AESCipher, generate_secret_key

pass_phrase = "hogefuga"
secret_key = generate_secret_key(pass_phrase)

# generate cipher
cipher = AESCipher(secret_key)

raw_text = "toi yeu hutech"
encrypt_text = cipher.encrypt(raw_text)
assert raw_text != encrypt_text

decrypt_text = cipher.decrypt(encrypt_text)
assert encrypt_text != decrypt_text
assert decrypt_text == raw_text

print(encrypt_text)

print(decrypt_text)
Exemple #10
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# % pip3 install Simple-AES-Cipher
# http://qiita.com/teitei_tk/items/0b8bae99a8700452b718
from simple_aes_cipher import AESCipher, generate_secret_key

import string
import random

passphrase = 'Hello world!'
cipher = AESCipher(generate_secret_key(passphrase))

message = 'I love python.'
enc = cipher.encrypt(message)
dec = cipher.decrypt(enc)

print(enc)
print(dec)

randomkey = ''
for i in range(64):
    randomkey = randomkey + random.choice(string.ascii_letters +
                                          string.digits + string.punctuation)
print(randomkey)