Thanks for the updates and giving the code a closer look. It may just
be my local configuration (I'll play with the code once I get it on
the live server), but I cannot get past the "ordinal not in
range(128)" error without performing two base64 encodings. I'm sure
this is why I have to decode twice, but every combination of base64 +
encString returns the same error unless I (1) encode the received
passport with base64, (2) then encString, (3) then encode the encoded
string again with base64. I did rewrite the code to be a bit more
streamlined. Do you think this will solve the possibility for an
unencrypted passport to be re-saved to the database?

        def set_passport(self, passport):
                secret_key = settings.SECRET_KEY
                k = ezPyCrypto.key()
                k.importKey(secret_key)

                #raw = base64.b64encode(passport)
                #encPassport = k.encString(raw)
                #self.passport = base64.b64encode(encPassport)

                self.passport =
base64.b64encode(k.encString(base64.b64encode(passport)))

        def get_passport(self):
                secret_key = settings.SECRET_KEY
                k = ezPyCrypto.key()
                k.importKey(secret_key)

                #encrypted_passport = base64.b64decode(self.passport)
                #decrypted_passport = k.decString(encrypted_passport)
                #self.passport = base64.b64decode(decrypted_passport)
                #return self.passport

                return
base64.b64decode(k.decString(base64.b64decode(self.passport)))

Still redundant...but it seems like I'm merely returning self.passport
rather than changing it as before. Am I correct here?

On May 14, 11:06 pm, Forest Bond <[EMAIL PROTECTED]> wrote:
> On Mon, May 14, 2007 at 10:21:28AM -0400, Benjamin Slavin wrote:
> > I'd recommend doing:
> >     def get_passport(self)
> >         ....
> >         return k.decString(base64.b64decode(self.passport))
>
> Yes, I think I would normally approach this like:
>
> class MyModel(Model):
>     passport = CharField(maxlength = 256) # or whatever length is appropriate
>
>     def _get_unencrypted_passport(self):
>         return k.decString(base64.b64decode(self.passport))
>     def _set_unencrypted_passport(self, value):
>         self.passport = base64.b64encode(k.encString(value))
>     unencrypted_passport = property(
>       _get_unencrypted_passport, _set_unencrypted_passport)
>
> Or something like that.  (I'm not sure if k.encString is the right function
> call, so double-check that.)
>
> -Forest
>
>  signature.asc
> 1KDownload


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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