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)
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))
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')
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
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)
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()
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)
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)
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
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)
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)
#!/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)