Ben, thanks a lot, some good info here. The Satchmo project is a great
reference--I hadn't seen it before. I've followed most of your
suggestions, and am getting closer but still not there. For reference,
I've posted both my view[0] and my model[1].

The base64 bit seems to have eliminated the original error, thanks for
that tip. At this point, my model is saving but the passport column is
not getting inserted to. Essentially, all info BUT the passport is
being inserted into the database, and I'm not sure why (I'm not
receiving any errors).

I don't fully understand the difference between the Satchmo method and
the getter/setter method that you mentioned, as they seem more or less
the same to me. I've modeled my code as closely with the Satchmo
method as possible, as it was something concrete for me to work
against. I noticed they are only using property() on the retrieval
(decrypt) of the CC info, not on the setting (encrypt), so I've left
property() out of my code for now as I'm just trying to get data
inserted first (then I'll worry about retrieving it).

Any ideas as to why the passport is not being inserted?

[0] http://dpaste.com/10262/
[1] http://dpaste.com/10263/

On May 14, 1:55 am, "Benjamin Slavin" <[EMAIL PROTECTED]>
wrote:
> On 5/13/07, elemental <[EMAIL PROTECTED]> wrote:
>
> > UnicodeDecodeError at /register/
> > 'ascii' codec can't decode byte 0xb4 in position 0: ordinal not in
> > range(128)
>
> > For reference, here is the save portion of the model:
>
> > def save(self):
> >         key = ezPyCrypto.key(512)
> >         self.passport = key.encString(self.passport)
>
> First, I'd recommend making a slight modification to this... you're
> continually re-encrypting the passport information... so if you call
> .save() twice you'll get an double-encrypted .passport value.
>
> One option can be found in the Satchmo Project's handling of credit
> card data. [0]  They use a storeCC method and a decryptedCC property
> to handle encryption/decryption.
>
> Another option is to use getter and setter methods, and access them
> via a property... this way encryption and decryption are transparent
> operations (this may or may not be desirable, depending on your
> environment).
>
> So, for example:
> class YourModel(models.Model):
>     ...
>     encrypted_passport = models.CharField(...)
>     def get_passport(self):
>         #decrypt and return decrypted value
>     def set_passport(self, value):
>         #encrypt and store in self.encrypted_passport
>     passport = property(get_passport, set_passport)
>
> Getting back to your original question, this sounds like you're
> getting binary data back from encString (it looks like it's built on
> top of pycrypto[1], so that's likely).  You can try the following to
> convert it to ASCII text before saving it:
>     self.passport = key.encString(...).encode('base64')
>
> Then, just run .decode('base64') on the string before running decryption.
>
> Hope that helps,
>   - Ben
>
> [0]http://www.satchmoproject.com/trac/browser/satchmo/trunk/satchmo/paym...
> [1]http://www.amk.ca/python/code/crypto.html


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" 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/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to