开发者

Python. Output of crypto.cipher.blowfish and .AES can be translated neither into unicode (as sqlite wants), nor into hex

Okay, I'm totally new to Python, so I decided to make a simple app. Here is my encryption function:

from Crypto.Cipher import AES
def encPass(login, password):
    keyPhr=os.environ['HOME']+login
    hashObj = hashlib.md5()
    hashObj.update(keyPhr)
    keyPhr=hashObj.hexdigest()
    keyObj=AES.new(keyPhr)
    encPwd=keyObj.encrypt(password+'pssd')
    return encPwd

as you see, it gets login and pass, and encrypt pass with binding to pc.

The problem is when i try to feed encPws to sqlite3 and insert it into a table, it says:

sqlite3.ProgrammingError: You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings.

If i try to put encPwd in unicode() or hex():

TypeError: hex() argument can't be converted to hex
Unic开发者_如何学运维odeDecodeError: 'utf8' codec can't decode byte 0x9c in position 0: unexpected code byte

I guess it's because i'm newbie, but what should I do? The same with Blowfish instead of AES


You can use buffer and insert the encPwd as a blob.

Or you can use something like base64 to convert your encPwd to ASCII (which is a subset of UTF8) so you can insert it as a string.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜