Skip to content

Instantly share code, notes, and snippets.

@mcomisso
Last active August 29, 2015 14:22
Show Gist options
  • Select an option

  • Save mcomisso/fe86ccab87e77c6fa83c to your computer and use it in GitHub Desktop.

Select an option

Save mcomisso/fe86ccab87e77c6fa83c to your computer and use it in GitHub Desktop.
BM comment crypt test
from Crypto.Cipher import AES
import base64
import os
# the block size for the cipher object; must be 16, 24, or 32 for AES
BLOCK_SIZE = 16
mode = AES.MODE_ECB
secret = "1234567890123456" #os.urandom(BLOCK_SIZE)
# create a cipher object using the random secret
cipher = AES.new(secret,mode)
# encode a string
#tx=cipher.encrypt('1234567890123456')
#print base64.b64encode(tx)
myData="""{
comment = Ciao;
"complete_name" = "Matteo Comisso";
customer = "matteo-comisso";
recipe = "patate-duchessa";
timestamp = "1423663571.026645";
}{{{{{{{{{{{{{{{{{{{{{{{{{{{"""
encoded = cipher.encrypt(myData)
print 'Encrypted string:', base64.b64encode(encoded)
## DECRYPTER
mode = AES.MODE_ECB
cipher=AES.new(secret,mode)
decoded = cipher.decrypt(encoded)
print 'Decrypted string:', decoded.rstrip('{')
import base64, time, hashlib, json
from Crypto.Cipher import AES
#Data for next implementation
testRequest2 = "tIgFXqsNUAyG/mGZaqCfyDfIBEJm3OVVOCe0OPDIMC8/quxZmHiMt/u21rH5rv68thAIxIQNxcUnU7MJemX0tnL/zuZgoXxzwbCtfE2Qzn5naGLEc1ignp3ltY5OrH1v4b1pMXQJSOuM2HM1KmYlTUe+P7NwY7/+igbQlTpIqnhWsubOq65g6J+dzBsyQv3n1NYKwznf9gVOHlb4anK9F0+qmQRrxGqqYRzOYeJqDDo="
testRequest = "Bm2dbSLycsVGNmT65o/E6NQ2VBGIX4g63AeYsvnMAZzntG03MJaw3qch8h1vHx1o0O70XJf0x51NQOiLgDkzPMMj0GnXg0LlYG82EkIokBXF0RwBokB2BXwdPXRusRQFQPBDd72HMY+bIV/8hs4o1DhoRsy47Imcb209JudPPfn7TNbsZ0xcAqniMM+jk7LMntybb7yJ5X2/X7NFhzLz9q0b5UD2qdtAv6z1NEmXlVc="
#variables
secret = "PfK5/Q9b6q0/ZgMO"
padding='{'
# plainText = """"complete_name" = "Matteo Comisso";
# "customer" = "matteo-comisso";
# "timestamp" = "1423669409.095277";
# "recipe" = "patate-duchessa";
# "comment" = "Ciao, sono contetnto";
# {{{{{{{{"""
plainTextiOS = """"complete_name" = "Matteo Comisso";
"customer" = "matteo-comisso";
"timestamp" = "1423681696.130770";
"recipe" = "cestino-ai-frutti-di-èosco-crudista";
"comment" = "Ciao";"""
def decryptRequestData(codedString):
cipher = AES.new(secret, AES.MODE_ECB)
encryptedString = base64.b64decode(codedString)
paddedText = cipher.decrypt(encryptedString)
decryptedString = paddedText.rstrip(padding)
decryptedString = decryptedString.rstrip(';\n')
decryptedString = decryptedString.replace(" = ", ":").replace("\";\n", "\",")
decryptedString = urllib
return decryptedString
def encryptRequest(plainTextData):
cipher = AES.new(secret, AES.MODE_ECB)
encoded = cipher.encrypt(plainText)
return base64.b64encode(encoded)
encryptedRequest = encryptRequest(plainTextiOS)
decodedString = decryptRequestData(encryptedRequest)
jsonTag = "{ " + decodedString + " }"
testa = json.loads(jsonTag)
print testa["customer"]
print testa["comment"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment