actually, it's not that easy..... I gave up on lambdas for this
implementation, but it works out nicely
import gluon.contrib.aes as AES
import threading
import base64
import os
def w2p_encrypt(data):
key = 'asdsaddasdasdas'
key = pad(key[:32])
cipher, IV = AES_new(key)
encrypted_data = IV + cipher.encrypt(pad(data))
return base64.urlsafe_b64encode(encrypted_data)
def w2p_decrypt(data):
key = 'asdsaddasdasdas'
key = pad(key[:32])
data = base64.urlsafe_b64decode(data)
IV, data = data[:16], data[16:]
cipher, _ = AES_new(key, IV=IV)
data = cipher.decrypt(data)
data = data.rstrip(' ')
return data
db.define_table('t_test',
Field('f_field')
)
db.t_test.f_field.filter_in = lambda value : w2p_encrypt(value)
db.t_test.f_field.filter_out = lambda value : w2p_decrypt(value)
PS: may I suggest the secure_dumps and secure_loads from gluon.utils ? they
add signing the value and in any case the added length isn't going to take
that much space in addition to what's needed....in addition they take
pretty much any python object, so that can be useful too.....
In that case the implementation is a taddle bit less verbose....
from gluon.utils import secure_dumps, secure_loads
db.t_test.f_field.filter_in = lambda value : secure_dumps(value, 'your_key')
db.t_test.f_field.filter_out = lambda value : secure_loads(value, 'your_key'
)
--
---
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.