Hi all, I am trying to store one or more encrypted values into their respective fields, which has to be decrypted during retrieval process. The codes that I am trying to follow are from https://groups.google.com/forum/#!msg/web2py/uGFQD0PBefQ; however, I am getting ValueError
<type 'exceptions.ValueError'> Key length must be 16, 24 or 32 bytes referring to File "C:\Users\Maurice Ling\Desktop\cynote2-master\gluon\contrib\aes.py", line 94, in setkey else: ValueError: Key length must be 16, 24 or 32 bytes Here are the codes (attached as file) to replicate this problem that I faced: session.encryptkey = '12345678901234567890123456789012' from gluon.utils import secure_dumps, secure_loads def new_entry(): form = FORM(TABLE( TR('Title: ', INPUT(_type='text', _name='title', _size=80)), TR('Contents: ', TEXTAREA(_type='text', _name='contents'), TR('',INPUT(_type='submit', _name='SUBMIT'))))) if form.accepts(request.vars, session): print len(session.encryptkey) cydb.encrypted_entries.insert(title=form.vars.title, contents=form.vars.contents) redirect(URL(r=request, f='entries')) return dict(form=form) cydb = SQLDB('sqlite://cydb.db') cydb.define_table('encrypted_entries', SQLField('title'), SQLField('contents'), SQLField('modified_on', 'datetime', default=now)) cydb.encrypted_entries.contents.filter_in = lambda value: secure_dumps(value, session.encryptkey) cydb.encrypted_entries.contents.filter_out = lambda value: secure_loads(value, session.encryptkey) 1. I am sure that '12345678901234567890123456789012' is 32 bytes long, so I am not sure what is happening. 2. I am not able to use SQLFORM as there are other operations involved; hence, the above codes are just to replicate the error. Can anyone help? Thank you in advance. Regards Maurice -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
session.encryptkey = '12345678901234567890123456789012' from gluon.utils import secure_dumps, secure_loads def new_entry(): form = FORM(TABLE( TR('Title: ', INPUT(_type='text', _name='title', _size=80)), TR('Contents: ', TEXTAREA(_type='text', _name='contents'), TR('',INPUT(_type='submit', _name='SUBMIT'))))) if form.accepts(request.vars, session): print len(session.encryptkey) cydb.encrypted_entries.insert(title=form.vars.title, contents=form.vars.contents) redirect(URL(r=request, f='entries')) return dict(form=form) cydb = SQLDB('sqlite://cydb.db') cydb.define_table('encrypted_entries', SQLField('title'), SQLField('contents'), SQLField('modified_on', 'datetime', default=now)) cydb.encrypted_entries.contents.filter_in = lambda value: secure_dumps(value, session.encryptkey) cydb.encrypted_entries.contents.filter_out = lambda value: secure_loads(value, session.encryptkey)