

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
15 messages in com.googlegroups.django-usersRe: ordinal not in range(128) + ezPyC...| From | Sent On | Attachments |
|---|---|---|
| elemental | May 13, 2007 4:14 am | |
| Malcolm Tredinnick | May 13, 2007 4:32 am | |
| elemental | May 13, 2007 5:07 am | |
| Benjamin Slavin | May 13, 2007 10:55 am | |
| elemental | May 14, 2007 12:17 am | |
| elemental | May 14, 2007 1:59 am | |
| Malcolm Tredinnick | May 14, 2007 2:10 am | |
| elemental | May 14, 2007 2:40 am | |
| elemental | May 14, 2007 5:01 am | |
| Benjamin Slavin | May 14, 2007 6:27 am | |
| Forest Bond | May 14, 2007 7:02 am | |
| Benjamin Slavin | May 14, 2007 7:21 am | |
| Forest Bond | May 14, 2007 8:06 am | |
| elemental | May 14, 2007 6:33 pm | |
| Forest Bond | May 14, 2007 6:54 pm |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread 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) + ezPyCrypto | Actions... |
|---|---|---|
| From: | elemental (kai....@gmail.com) | |
| Date: | May 14, 2007 1:59:22 am | |
| List: | com.googlegroups.django-users | |
Update...
I think I've fixed the insert issue. The updated model is here:
Now, I just can't get the passport back out of the database :-)
I put together a quick view/template, and the passport is being returned as an empty string, with no errors.
The relavent part of the the model is:
def get_passport(self): secret_key = settings.SECRET_KEY k = ezPyCrypto.key() k.importKey(secret_key)
return(k.decString(self.passport))
decryptedPP = property(get_passport)
My view is really short, so I'll just post it here:
def list(request):
registrations = registerDiver.objects.all()
return render_to_response('list.html', { 'registrations' : registrations, }, context_instance=RequestContext(request))
and my template:
<ul> {% for diver in registrations %} <li>{{ diver.first_name }} | {{ diver.decryptedPP }}</li> {% endfor %} </ul>
Any ideas why decryptedPP is blank?
Thanks, Kai
On May 14, 3:17 pm, elemental <kai....@gmail.com> wrote:
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" <benj...@gmail.com> wrote:
On 5/13/07, elemental <kai....@gmail.com> 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







