On Wed, Mar 3, 2010 at 8:30 AM, Mariano Mara <[email protected]> wrote:
> Excerpts from gazza's message of Wed Feb 10 18:08:12 -0300 2010:
>> Hello,
>>
>> I need to encrypt a couple of table entries of sql-alchemy database.
>> I could cycle through the entries and encrypt my own, however does
>> pylons offer an api to do this?
>>
>> Much appreciated,
>> Garyc
>>
> Several database vendors offer data encryption on the db directly. Why
> are you trying to encrypt? To protect the data from a DBA? Sysadmin?
> External forces?

Another option would be an encrypted column type.  You can subclass
any of the standard types to automatically convert data going into the
database and out of it.

http://www.sqlalchemy.org/docs/reference/sqlalchemy/types.html?highlight=typedecorator#custom-types

import sqlalchemy.types as types

class MyType(types.TypeDecorator):
    # Prefixes Unicode values with "PREFIX:" on the way in and
    # strips it off on the way out.

    impl = types.Unicode

    def process_bind_param(self, value, dialect):
        return "PREFIX:" + value

    def process_result_value(self, value, dialect):
        return value[7:]

    def copy(self):
        return MyType(self.impl.length)

'impl' is the original type being subclassed.  The first method is for
values going into the database; the second is for values coming out.
The third is used to pass constructor args through to copies of the
instance; e.g., ``sa.types.Unicode(8)``.  Since encrypted data may
have any arbitrary bytes in it, you may have to use Binary as the base
type.

-- 
Mike Orr <[email protected]>

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to