It rises an exception now: *ValueError: Plaintext length must be multiple
of 16*
I believe it's this part of aes:
if len(data) % self.block_size != 0:
raise ValueError, "Input length must be multiple of 16"
Not sure what's wrong.
On Tuesday, June 25, 2013 2:27:11 PM UTC+2, Massimo Di Pierro wrote:
>
> Sorry. try this:
>
> import gluon.contrib.aes as AES
> key = "your encryption key"
> IV = ' '*16
> db.table.field.filter_in = lambda data,key=key,iv=IV:
> AES.new(key,AES.MODE_CBC,iv).encrypt(data)
> db.table.field.filter_out = lambda data,key=key,iv=IV:
> AES.new(key,AES.MODE_CBC,iv).decrypt(data)
>
>
> On Tuesday, 25 June 2013 07:08:41 UTC-5, lesssugar wrote:
>>
>> OK, I get it. However, using the code I get:
>>
>> *AttributeError: type object 'AES' has no attribute 'new'*
>>
>> On Tuesday, June 25, 2013 2:00:06 PM UTC+2, Massimo Di Pierro wrote:
>>>
>>> You cannot use CRYPT for this purpose. That is a one way hash. The
>>> original plaintext cannot be recovered.
>>>
>>> You need a symmetric cypher. Web2py comes with the gluon/contrib/aes.py
>>>
>>> from gluon.contrib.aes import AES
>>> key = "your encryption key"
>>> IV = ' '*16
>>> db.table.field.filter_in = lambda data,key=key,iv=iv:
>>> AES.new(key,AES.MODE_CBC,iv).encrypt(data)
>>> db.table.field.filter_out = lambda data,key=key,iv=iv:
>>> AES.new(key,AES.MODE_CBC,iv).decrypt(data)
>>>
>>>
>>>
>>> On Tuesday, 25 June 2013 06:11:49 UTC-5, lesssugar wrote:
>>>>
>>>> I have values I would like to store encrypted in my db after user
>>>> inserts them. When displayed, the data should get decrypted.
>>>>
>>>> All I know about encryption in web2py is that it uses HMAC+SHA512 by
>>>> default to store password in auth_user table. How do I customize it to
>>>> achieve my goal?
>>>>
>>>> *EDIT*
>>>> I found this: *requires=CRYPT(digest_alg='sha512')* - but I think it's
>>>> only crating a hash, right? I guess I need a key to encrypt/decrypt. And
>>>> how do I get the values in Row object decrypted after I perform a select?
>>>> Can't find much about implementing such mechanism in web2py, unfortunately.
>>>>
>>>
--
---
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.