[Python-Dev] Why can't I encode/decode base64 without importing a module?
dholth at gmail.com
Thu Apr 25 16:25:21 CEST 2013
On Thu, Apr 25, 2013 at 10:07 AM, Barry Warsaw <barry at python.org> wrote:
> On Apr 25, 2013, at 03:34 PM, Lennart Regebro wrote:
>>In the case of JSON objects, they are intended for data exchange, and
>>hence in the end need to be byte strings.
> Except that they're not.
> Python-Dev mailing list
> Python-Dev at python.org
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/dholth%40gmail.com
What am I doing wrong in this JSON crypto signature verification
snippet that features many conversions between binary and text?
recipients = jwsjs["recipients"]
encoded_payload = binary(jwsjs["payload"])
headers = 
for recipient in recipients:
h = binary(recipient["header"])
s = binary(recipient["signature"])
header = json.loads(native(urlsafe_b64decode(h)))
vk = urlsafe_b64decode(binary(header["jwk"]["vk"]))
secured_input = b".".join((h, encoded_payload))
sig = urlsafe_b64decode(s)
sig_msg = sig+secured_input
verified_input = native(ed25519ll.crypto_sign_open(sig_msg, vk))
verified_header, verified_payload = verified_input.split('.')
verified_header = binary(verified_header)
decoded_header = native(urlsafe_b64decode(verified_header))
verified_payload = binary(verified_payload)
# only return header, payload that have passed through the crypto library.
payload = json.loads(native(urlsafe_b64decode(verified_payload)))
return headers, payload
More information about the Python-Dev