This commit is contained in:
Luke Rogers 2014-02-21 14:55:33 +13:00
parent 2d90288856
commit 87b1d3d7f4
6 changed files with 21 additions and 13 deletions

View file

@ -69,7 +69,8 @@ def encrypt(inp, bot=None, db=None, notice=None):
# store the encoded text and IV in the DB for decoding later
db.execute("insert or replace into encryption(encrypted, iv)"
"values(?,?)", (encoded, iv_encoded))
"values(:encoded,:iv)", {'encoded': encoded,
'iv': iv_encoded})
db.commit()
return encoded
@ -97,7 +98,7 @@ def decrypt(inp, bot=None, db=None, notice=None):
# get the encoded IV from the database and decode it
iv_encoded = db.execute("select iv from encryption where"
" encrypted=?", (text,)).fetchone()[0]
" encrypted=:text", {'text': text}).fetchone()[0]
iv = base64.b64decode(iv_encoded)
# create AES cipher, decode text, decrypt text, and unpad it