Well, seems like I keep answering my own questions, but I'll post what
I found here in case it helps anybody else...
The solution:
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
This works but notice I have to decode with base64 twice. Similarly, I
have to encode with base64 twice on set_passport. I'm not sure why--
and it certainly seems like something is slightly amiss-- but it does
work as best I can tell. Any explanation for needing encode/decode
twice?
Nevertheless, very stoked to have this working...was a big
breakthrough for me in terms of understanding how django works. Many
thanks to Malcom and Benjamin.
On May 14, 5:40 pm, elemental <[EMAIL PROTECTED]> wrote:
> Hi Malcom,
>
> I was unaware of sys.stderr.write, very handy--thanks
> (obviously, I'm still working my way through python/django).
>
> I'm indeed on the development server, and using sys.stderr.write, I
> can conclude that:
>
> - the key is being imported from the settings file
> - self.passport contains the encrypted passport
>
> The problem seems to lie in :
>
> return(k.decString(self.passport))
>
> as nothing is printed in the console with
> sys.stderr.write(k.decString(self.passport).
>
> Also, I'm not sure what I would actually input to test if
> k.importKey(secret_key) is gathering info, so the problem may be
> there.
>
> secret_key = settings.SECRET_KEY
> k = ezPyCrypto.key()
> k.importKey(secret_key)
>
> sys.stderr.write(k)
>
> This doesn't print anything to the console, but it also doesn't seem
> as if it should print anything. Ideas? Sorry to keep pestering, but
> there's a mental bridge I haven't quite crossed yet in terms of how
> this is all working together. Thanks again.
>
> On May 14, 5:11 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
> wrote:
>
> > On Mon, 2007-05-14 at 08:59 +0000, elemental wrote:
> > > Update...
>
> > > I think I've fixed the insert issue. The updated model is here:
>
> > >http://dpaste.com/10264/
>
> > > 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?
>
> > Put some diagnostic output into get_passport() to see if it (a) gets
> > called and (b) extracts the information you think it should be.
>
> > You can print to sys.stderr, for example, and the result will show up on
> > the console (if you are using the development server) or in Apache's
> > error log (if you are using mod_python -- although remember to call
> > sys.stderr.flush() in that case because mod_python buffers stderr) or
> > somewhere if you are using another webserver. Typically, though,
> > sys.stderr should go somewhere sensible.
>
> > Drop in a print statement to see if you call the method. Drop in another
> > one to see if k.importKey() actually gathers any information. Does
> > self.passport contain something? Does k.decString() do anything with
> > that something or perhaps raise an exception? Not until you know that
> > get_passport() is returning the right value will you be in a position to
> > work out why the template isn't displaying that value.
>
> > Regards,
> > Malcolm
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---