def decr(value, password): m = sha256() m.update(password) passwd = m.digest() iv = m.digest()[::2] cipher = aes.AESModeOfOperationCFB(passwd, iv=iv) decrypted = cipher.decrypt(b64decode(value)) return decrypted[:-ord(decrypted[-1:])].decode('ascii')
def encr(value, password): m = sha256() m.update(password) key = m.digest() iv = m.digest()[::2] pad = 16 - len(value) % 16 raw = value + pad * chr(pad) cipher = aes.AESModeOfOperationCFB(key, iv=iv) return b64encode(cipher.encrypt(raw)).decode('ascii')
def decr(value): m = sha256() m.update(password) passwd = m.digest() iv = m.digest()[::2] cipher = aes.AESModeOfOperationCFB(passwd, iv=iv) decrypted = cipher.decrypt(b64decode(value)) try: return decrypted[:-ord(decrypted[-1:])].decode('utf-8') except UnicodeDecodeError: print('Password is probably incorrect') exit(1)