Skip to content

Instantly share code, notes, and snippets.

@mattbasta
Created March 22, 2017 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mattbasta/84df1616ab07133a3da42f9c3ea9001f to your computer and use it in GitHub Desktop.
Save mattbasta/84df1616ab07133a3da42f9c3ea9001f to your computer and use it in GitHub Desktop.
import codecs
import hashlib
import json
import pyaes
from django.conf import settings
from pinecast.helpers import gravatar
def get_canny_token(req):
if not req.user:
return None
user_data = {
'avatarURL': gravatar(req.user.email),
'email': req.user.email,
'id': req.user.id,
'name': req.user.email,
}
plaintext = json.dumps(user_data)
dig = hashlib.md5(settings.CANNY_SSO_KEY.encode('utf-8')).digest()
aes = pyaes.AESModeOfOperationECB(dig)
ciphertext = b''
for i in range(0, len(plaintext), 16):
ciphertext += aes.encrypt(plaintext[i:16].rjust(16))
return codecs.encode(ciphertext, 'hex_codec').decode('utf-8')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment