Skip to content

Commit 5493701

Browse files
author
Leif Johansson
committed
fixed b64 enc/dec once and for all
1 parent aa37499 commit 5493701

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

src/xmlsec/crypto.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,16 +226,22 @@ def sign(self, data, hash_alg=None):
226226
import requests
227227
import json
228228
url = '{!s}/rawsign'.format(self._keyspec)
229-
r = requests.post(url, json=dict(mech='RSAPKCS1', data=base64.encodestring(data)))
229+
if not isinstance(data, six.binary_type):
230+
data = data.encode("utf-8")
231+
data = base64.b64encode(data)
232+
r = requests.post(url, json=dict(mech='RSAPKCS1', data=data))
230233
if r.status_code != requests.codes.ok:
231234
r.raise_for_status()
232235
msg = r.json()
233-
if not 'signed' in msg:
236+
if 'signed' not in msg:
234237
raise ValueError("Missing signed data in response message")
235-
return base64.encodestring(msg['signed'])
238+
signed_msg = msg['signed']
239+
if not isinstance(signed_msg, six.binary_type):
240+
signed_msg = signed_msg.encode("utf-8")
241+
return base64.b64decode(signed_msg)
236242
except Exception as ex:
237-
from traceback import print_exc
238-
print_exc(ex)
243+
from traceback import format_exc
244+
log.debug(format_exc())
239245
raise XMLSigException(ex)
240246

241247

0 commit comments

Comments
 (0)