15 messages in com.googlegroups.django-usersRe: ordinal not in range(128) + ezPyC...
FromSent OnAttachments
elementalMay 13, 2007 4:14 am 
Malcolm TredinnickMay 13, 2007 4:32 am 
elementalMay 13, 2007 5:07 am 
Benjamin SlavinMay 13, 2007 10:55 am 
elementalMay 14, 2007 12:17 am 
elementalMay 14, 2007 1:59 am 
Malcolm TredinnickMay 14, 2007 2:10 am 
elementalMay 14, 2007 2:40 am 
elementalMay 14, 2007 5:01 am 
Benjamin SlavinMay 14, 2007 6:27 am 
Forest BondMay 14, 2007 7:02 am 
Benjamin SlavinMay 14, 2007 7:21 am 
Forest BondMay 14, 2007 8:06 am 
elementalMay 14, 2007 6:33 pm 
Forest BondMay 14, 2007 6:54 pm 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: ordinal not in range(128) + ezPyCryptoActions...
From:elemental (kai.@gmail.com)
Date:May 14, 2007 6:33:58 pm
List:com.googlegroups.django-users

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 <for@alittletooquiet.net> 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