From 4ba29b47079dc539ab468af698e525345edf1364 Mon Sep 17 00:00:00 2001 From: Jeremy Bowman Date: Wed, 22 Nov 2017 11:55:44 -0500 Subject: [PATCH] Convert unicode to bytes for RSA encryption --- lms/djangoapps/verify_student/ssencrypt.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lms/djangoapps/verify_student/ssencrypt.py b/lms/djangoapps/verify_student/ssencrypt.py index 7d1b9a8128..1a6eb8d716 100644 --- a/lms/djangoapps/verify_student/ssencrypt.py +++ b/lms/djangoapps/verify_student/ssencrypt.py @@ -23,6 +23,7 @@ import hmac import logging import os from hashlib import md5, sha256 +from six import text_type from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives import serialization @@ -105,6 +106,10 @@ def rsa_encrypt(data, rsa_pub_key_bytes): """ `rsa_pub_key_bytes` is a byte sequence with the public key """ + if isinstance(data, text_type): + data = data.encode('utf-8') + if isinstance(rsa_pub_key_bytes, text_type): + rsa_pub_key_bytes = rsa_pub_key_bytes.encode('utf-8') if rsa_pub_key_bytes.startswith(b'-----'): key = serialization.load_pem_public_key(rsa_pub_key_bytes, backend=default_backend()) elif rsa_pub_key_bytes.startswith(b'ssh-rsa '):