python Encrypt and Decrypt module win32crypt sqlite3

by: alexdotis, 8 years ago


I use python 2.7 and I want to encrypt and decrypt with win32crypt module:

import win32crypt
import sqlite3

def crypto(password):

    encrypt = win32crypt.CryptProtectData(password)
    return encrypt

def createdb():

    conn = sqlite3.connect("accounts.db")
    c = conn.cursor()
    c.execute('''CREATE TABLE accounts (username text , password text)''')
    conn.create_function('encrypt', 1, crypto)
    result = c.execute("INSERT INTO accounts(username,password) VALUES(?,encrypt(?))",(myusername,mypassword))

    conn.commit()
    conn.close()

def decrypt():

    conn = sqlite3.connect("accounts.db")
    c = conn.cursor()
    result = c.execute("SELECT * FROM accounts")

    for result in c.fetchall():
        print result
        password = win32crypt.CryptUnprotectData(result[1])
        print password

createdb()
decrypt()


With this code, I get the following error:

line 35, in decrypt password = win32crypt.CryptUnprotectData(result[1]) error: (87, 'CryptProtectData', 'xc7 xf0xe1xf1xdcxecxe5xf4xf1xefxf2 xe5xdfxedxe1xe9 xe5xf3xf6xe1xebxecxddxedxe7.')

What am I doing wrong?



You must be logged in to post. Please login or register an account.