Skip to content

Instantly share code, notes, and snippets.

@satiani
Created May 27, 2014 16:32
Show Gist options
  • Save satiani/fbc1fb05a8373f16c7c0 to your computer and use it in GitHub Desktop.
Save satiani/fbc1fb05a8373f16c7c0 to your computer and use it in GitHub Desktop.
import base64
import urllib
import codecs
from Crypto.Cipher import AES
from Crypto.Hash import MD5
temp_token = "value from propay"
temp_token = codecs.encode(temp_token, 'utf-8')
settings = {
'AuthToken' : temp_token,
'PayerId' : propay_payer_id,
'PaymentProcessType' : 'CreditCard',
'ProcessMethod' : 'None',
'PaymentMethodStorageOption' : 'Always',
'ReturnURL' : "http://example_url.com/example"
}
encoded_settings = urllib.urlencode(settings)
encoded_settings = codecs.encode(encoded_settings, 'utf-8')
md = MD5.new()
md.update(temp_token)
key = md.digest()
iv = key
block_size = 16
pad = block_size - (len(encoded_settings) % block_size)
encoded_settings = encoded_settings + pad*chr(pad)
aes = AES.new(key, IV=iv, mode=AES.MODE_CBC)
settings_cipher = base64.b64encode(aes.encrypt(encoded_settings))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment