Esempio n. 1
0
def post_signup(request):
    if request.method == 'POST':
        username = request.POST["username"]
        email = request.POST["email"]
        password = request.POST["psw"]
        confirmation = request.POST["psw-repeat"]
        if password != confirmation:
            return render(request, "rambleapp/signup_in.html",
                          {"message": "Passwords must match."})
        # Salted password SRM
        #password = bytes(password, 'utf-8')
        if not type(password) == bytes:
            password = password.encode()
        size = 10
        salt = os.urandom(size)
        pass_key = pbkdf2_hmac("sha256", password, salt, 50000, 32)
        pass_key = str(pass_key)
        #print(type(pass_key))
        #pass_key = unicode(pass_key, errors='ignore')
        #pass_key = pass_key.encode("utf8","ignore")
        #pass_key = to_bytes(pass_key.encode('utf-8'))
        #try:
        #    pass_key = pass_key.decode()
        #    print("Here")
        #except (UnicodeDecodeError, AttributeError):
        #    print("Error")
        #    pass

        key = 'Store login securely'
        key = generate_secret_key(key)
        cipher = AESCipher(key)
        encrypt_text = cipher.encrypt(pass_key)
        print(encrypt_text)
        assert pass_key != encrypt_text

        #pass_key = cipher.encrypt(plain_text=pass_key)
        # Salted password SRM

        try:
            user = Auth_User.objects.create_user(
                username, email, encrypt_text)  #Salted password SRM
            user.save()
        except IntegrityError as e:
            print(e)
            return render(request, "rambleapp/signup_in.html",
                          {"message": "Email address already taken."})
        user = authenticate(request, username=username,
                            password=encrypt_text)  #Salted password SRM
        if user is not None:
            auth_login(request,
                       user,
                       backend="django.contrib.auth.backends.ModelBackend")
        #user = Auth_User.objects.get(username=username).pk
        #form = ProfileForm(request.POST, request.FILES)
        #template = loader.get_template('rambleapp/make_profile.html')
        #context = {}
        #return HttpResponse(template.render(context, request))
        return redirect(make_profile)
    return HttpResponseForbidden('allowed only via POST')
Esempio n. 2
0
def connected(tag):
    print >> sys.stderr, 'tag touched. input password and send return'
    obj = AESCipher(tagops.read_password(tag))
    ciphertext = obj.encrypt(raw_input())
    b64ciphertext = base64.b64encode(ciphertext)
    print(b64ciphertext)
    sys.exit(0)
    return True
Esempio n. 3
0
    def __init__(self):

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

        # generate cipher
        self.cipher = AESCipher(secret_key)
    def encrypts(self):
        message = self.t1.get("1.0", tk.END)
        pass_phrase = self.tkey.get()
        secret_key = generate_secret_key(pass_phrase)
        print(secret_key)
        cipher = AESCipher(secret_key)
        ciphertext = cipher.encrypt(message)

        self.t2.delete('1.0', tk.END)
        self.t2.insert("1.0", ciphertext)
Esempio n. 5
0
def aes_encryption():

    # padding, initialization vectors and password derivation is handled by the library
    key = generate_secret_key(password)
    cipher = AESCipher(key)
    local_file_reader = open(input_file, 'r')
    local_file_data = local_file_reader.read()
    local_file_reader.close()
    local_file_writer = open(tmp_data_encrypted, 'w')
    local_file_writer.write(cipher.encrypt(local_file_data))
    local_file_writer.close()
Esempio n. 6
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)
Esempio n. 8
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
Esempio n. 9
0
    def gen_passfile(passfile='.gmailsend', relativepath=True):
        if (relativepath):
            passfile = os.path.dirname(__file__) + '/' + passfile

        print('''
passfile includes all infromation to access your mail account.
PLEASE BE AWARE THE RISK!

If you understand the risk, please type "yes" and enter.
''')
        understood = input()
        if (understood.lower() == 'yes'):
            print('''
*******************************************************
passphrase will be appeared in plain text in your code.
*******************************************************
''')

            passphrase = input('passphrase: ')

            host = input('smtp host (defult: smtp.gmail.com): ')
            if (host == ''):
                host = 'smtp.gmail.com'

            port = input('port (defult: 465): ')
            if (port == ''):
                port = '465'
            account = input('account: ')

            flg = True
            while (flg):
                password = getpass('password: '******'password (confirm): ')
                if (password == password_conf):
                    flg = False
                else:
                    print('Not matched...')

            cipher = AESCipher(generate_secret_key(passphrase))

            host = cipher.encrypt(host)
            port = cipher.encrypt(port)
            account = cipher.encrypt(account)
            password = cipher.encrypt(password)
            with open(passfile, 'w') as fout:
                fout.write(host + '\n')
                fout.write(port + '\n')
                fout.write(account + '\n')
                fout.write(password + '\n')
            os.chmod(passfile, S_IRUSR | S_IWUSR)
Esempio n. 10
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)
Esempio n. 11
0
def login(request):
    user = request.POST.get ('user', False)
    pswd = request.POST.get('pswd', False)
    if request.user.is_authenticated: 
        if request.user.is_active: 
            return redirect("index")
    # Salted password SRM
    size = 10
    salt = os.urandom(size)
    if user is not False and pswd is not False:
        pass_key = pbkdf2_hmac("sha256", pswd, salt, 50000, 32)
        pass_key = AESCipher.encrypt(pass_key)
    # Salted password SRM
    try:
        twitter_login = user.social_auth.get(provider='twitter')
    except UserSocialAuth.DoesNotExist:
        twitter_login = None
    except AttributeError:
        twitter_login = None
    template = loader.get_template('magiclink/login_ml.html')

    if twitter_login is None and user is not False and pswd is not False: 
        user = authenticate(request, username=user, password=pass_key)
    
    posts = Post.objects.all().order_by('-post_timestamp')
    posts_and_likes = [(post, len(Like.objects.filter(post_id=post))) for post in posts]
   
    context = {'twitter_login': twitter_login, 'posts': posts, 'posts_and_likes': posts_and_likes, 'user_details': user}
    return HttpResponse(template.render(context, request))
Esempio n. 12
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
Esempio n. 13
0
class AES:
    pass_phrase = ""
    i = 0
    while i < 32:
        if i % 2 == 0:
            pass_phrase += "1"
        else:
            pass_phrase += "0"
        i += 1
    secret_key = generate_secret_key(pass_phrase)
    cipher = AESCipher(secret_key)
    raw_text = ""
    encrypt_text = ""
Esempio n. 14
0
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)
Esempio n. 15
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
Esempio n. 16
0
 def Send(self, args):
     self.gettext.configure(state=NORMAL)
     text = self.sendtext.get()
     if text == "": text = " "
     self.gettext.insert(END, 'Me >> %s \n' % text)
     self.sendtext.delete(0, END)
     pass_phrase = ""
     i = 0
     while i < 32:
         a = random.randint(0, 1)
         pass_phrase += str(a)
         i += 1
     variable = AES()
     variable.pass_phrase = pass_phrase
     variable.secret_key = generate_secret_key(pass_phrase)
     variable.cipher = AESCipher(variable.secret_key)
     variable.encrypt_text = variable.cipher.encrypt(text)
     data_string = pickle.dumps(variable)
     self.client.send(data_string)
     self.sendtext.focus_set()
     self.gettext.configure(state=DISABLED)
     self.gettext.see(END)
Esempio n. 17
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)
Esempio n. 18
0
 def setUp(self):
     pass_phrase = self._choice_randome_string()
     self.secret_key = generate_secret_key(pass_phrase)
     self.cipher = AESCipher(self.secret_key)
Esempio n. 19
0
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)
 def _get_cipher(self, key_length=128):
     return AESCipher(self.secret_key, block_size=key_length)
Esempio n. 21
0
from simple_aes_cipher import AESCipher, generate_secret_key

pass_phrase = "identify-application"
secret_key = generate_secret_key(pass_phrase)
print(secret_key)
cipher = AESCipher(secret_key)


def get_encrypted_val(plain_txt):
  encrypt_text = cipher.encrypt(plain_txt)
  return plain_txt


def get_decrypted_val(encrypted_txt):
  decrypt_text = cipher.decrypt(encrypted_txt)
  return encrypted_txt
Esempio n. 22
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)