Beispiel #1
0
def login():
    cryptor = rncryptor.RNCryptor()
    data = request.get_json()
    username = data['username']
    cur.execute("select * from user where username = %s", (username, ))
    myresult = cur.fetchall()
    print(myresult)
    db_data = myresult[0]
    print(data['password'])
    password = data['password']

    #decrypted_data = base64.b64decode(password)
    #decrypted_data = message_bytes.decode('ascii')
    #decrypted_data = base64.decodestring(data['password'])
    #print(str(decrypted_data))
    if check_password_hash(db_data['password'], password):
        apiResponse['data'] = "login successfully"
        apiResponse['statusCode'] = 200
        response = make_response(apiResponse)
        token = jwt.encode(
            {
                'public_id': username,
                'user_id': db_data['user_id'],
                'exp':
                datetime.datetime.utcnow() + datetime.timedelta(minutes=30)
            }, app.config['SECRET_KEY'])
        response.set_cookie('token', token, max_age=90 * 60 * 60 * 24)
        return response
    else:
        apiResponse['data'] = "Failed"
        apiResponse['statusCode'] = 300
    return apiResponse
Beispiel #2
0
def decrypt_share(enc_file, passcode):
    cryptor = rncryptor.RNCryptor()
    filename = enc_file
    f = open(filename, mode='rb')
    data = f.read()
    decrypted_data = cryptor.decrypt(data, passcode)
    f.close()
    return decrypted_data
Beispiel #3
0
def encrypt_share(text_file, passcode):
    cryptor = rncryptor.RNCryptor()
    filename = text_file
    f = open(filename, mode='rb')
    data = f.read()
    encrypted_data = cryptor.encrypt(data, passcode)
    f.close()
    return encrypted_data
Beispiel #4
0
 def __init__(self, salt):
     self.salt = salt
     if self.salt:
         self.salt = hashlib.sha256(str.encode(self.salt)).hexdigest()
         logging.info("salt is set.")
     else:
         logging.info("No salt provided. It won't be possible to "
                      "decrypt sensitive fields.")
     self.rn_cryptor = rncryptor.RNCryptor()
    def decrypt(self):
        """Decrypt the hashed data using password
        :return: The decrypted data
        :rtype: bytes
        """
        cryptor = rncryptor.RNCryptor()
        decrypted_data = cryptor.decrypt(self.data, self.password).encode()
        self.data = decrypted_data

        return self.data
    def encrypt(self):
        """Encrypt the data using PBKDF2 + salt function.
        :return: The encrypted data
        :rtype: bytes
        """
        cryptor = rncryptor.RNCryptor()
        encrypted_data = cryptor.encrypt(self.data, self.password)
        self.data = encrypted_data

        return self.data
Beispiel #7
0
def decrypt_data(data, password):
    cryptor = rncryptor.RNCryptor()
    decrypted_data = None
    try:
        decrypted_data = cryptor.decrypt(data, password)
    except rncryptor.DecryptionError as e:
        print "Decrypted file seems to be invalid! (probably wrong e-mail used?)"
        raise e

    return decrypted_data
Beispiel #8
0
def decryptNote(noteContent, password):

    # Filtering content
    noteContent = noteContent.replace(safeglobals.ENCRYPTED_PREFIX,
                                      "").replace(safeglobals.ENCRYPTED_SUFFIX,
                                                  "")
    array = noteContent.split("__")
    noteContent = array[1]

    cryptor = rncryptor.RNCryptor()
    content = base64.b64decode(noteContent)
    decrypted_data = cryptor.decrypt(content, password)
    return decrypted_data
Beispiel #9
0
 def decrypt_mail_password(self):
     """
     Decrypts the encrypted password with the app´s secret key.
     :return: decrypted password
     """
     if not has_app_context:
         raise ValueError("No App Context")
     secret_key = current_app.config['SECRET_KEY']
     cryptor = rncryptor.RNCryptor()
     decrypted_password = cryptor.decrypt(self.mail_password_encrypted,
                                          secret_key)
     current_app.logger.info("Successfully decrypted mail password.")
     return decrypted_password
Beispiel #10
0
def convert_encrypt(intent_file, passcode):
    s = 'EXECUTE intent: '
    cryptor = rncryptor.RNCryptor()
    devicelists = ''
    with open(intent_file, mode='r') as f:
        jdatas = f.read()
    f.close()
    k = jdatas.find(s)
    if (k != -1):
        jdatas = jdatas[len(s):]
    devicelists = parse_to_devices(json.loads(jdatas))
    print("DEBUG: ", devicelists)
    encrypted_data = cryptor.encrypt(devicelists, passcode)
    return encrypted_data
Beispiel #11
0
    def encrypt_mail_password(self, password):
        """
        Accepts the clear text password and stores it encrypted with the app´s secret key.

        :param password: clear text password
        :return:
        """
        if not has_app_context:
            raise ValueError("No App Context")
        secret_key = current_app.config['SECRET_KEY']
        cryptor = rncryptor.RNCryptor()
        encrypted_password = cryptor.encrypt(password, secret_key)
        self.mail_password_encrypted = encrypted_password
        db.session.commit()
        current_app.logger.info("Successfully encrypted mail password.")
Beispiel #12
0
def decryptFileData(data, password):
    cryptor = rncryptor.RNCryptor()
    decrypted_data = cryptor.decrypt(data, password)
    return decrypted_data
Beispiel #13
0
def decryptString(string, key):
    cryptor = rncryptor.RNCryptor()
    encrypted_string = base64.b64decode(string)
    decrypted_string = cryptor.decrypt(encrypted_string, key)
    return decrypted_string
Beispiel #14
0
def encryptString(string, key):
    cryptor = rncryptor.RNCryptor()
    encrypted_string = cryptor.encrypt(string, key)
    return base64.b64encode(encrypted_string)
Beispiel #15
0
def _decrypt(encrypted, passphrase):
    """Decrypt python object"""
    cryptor = rncryptor.RNCryptor()
    return json.loads(cryptor.decrypt(encrypted, passphrase))
Beispiel #16
0
def _encrypt(data, passphrase):
    """Encrypt python object"""
    cryptor = rncryptor.RNCryptor()
    return cryptor.encrypt(json.dumps(data), passphrase)
Beispiel #17
0
def encryptNote(noteContent, password):
    cryptor = rncryptor.RNCryptor()
    encrypted_data = cryptor.encrypt(noteContent, password)
    return base64.b64encode(encrypted_data)
Beispiel #18
0
def encryptData(data, password):
    cryptor = rncryptor.RNCryptor()
    encrypted_data = cryptor.encrypt(data, password)
    return encrypted_data
Beispiel #19
0
 def decrypt_user_id(encrypted_id, key):
     cryptor = rncryptor.RNCryptor()
     return cryptor.decrypt(base64.b64decode(encrypted_id), key)
#!/usr/bin/python3
###
# Above line makes the file executable with Python3
# To make the file fully execuatble wite:" ./py_pwm.py " command in terminal do the following
# in terminal "chmod 755 py_pwm.py"
# ALTERNATIVLY you can always just type "python3 py_pwm.py"
###
import json

# PySimpleGUI has to be installed "pip3 install pysimplegui"
import PySimpleGUI as sg

# The library rncryptor has to be installed "pip3 install rncryptor"
import rncryptor
cryptor = rncryptor.RNCryptor()

# The encrypted file that contains the password, call it something else if you wish.
# It has to reside in the same folder as this script
data_file = 'my_manager.dat'

# Change the colorsheme of the GUI ref: https://www.geeksforgeeks.org/themes-in-pysimplegui/
sg.theme('DarkBlack1')

# Not logged in yet
login = False


# Figure out if passwordfile exists
def startup_check():
    try:
        with open(data_file, "rb") as fc:
Beispiel #21
0
def decrypt(encrypted_string: str, password: str) -> str:
    return rncryptor.RNCryptor().decrypt(b64decode(
        encrypted_string.encode("utf-8")),
                                         password=password)
Beispiel #22
0
 def encrypt_user_id(self, key):
     cryptor = rncryptor.RNCryptor()
     encrypted_string = cryptor.encrypt(str(self.id), key)
     return base64.b64encode(encrypted_string)
Beispiel #23
0
def encrypt(string_to_encrypt: str, password: str) -> str:
    return b64encode(rncryptor.RNCryptor().encrypt(
        data=string_to_encrypt, password=password)).decode("utf-8")
def test_encrypt_decrypt_methods_should_be_correct(data, password):
    cryptor = rncryptor.RNCryptor()
    encrypted_data = cryptor.encrypt(data, password)
    decrypted_data = cryptor.decrypt(encrypted_data, password)
    assert data == decrypted_data
Beispiel #25
0
def decrypt_note(noteContent, password):
    cryptor = rncryptor.RNCryptor()
    content = base64.b64decode(noteContent)
    decrypted_data = cryptor.decrypt(content, password)
    return decrypted_data