Skip to content

Instantly share code, notes, and snippets.

@evgeni
Last active December 12, 2015 12:18
Show Gist options
  • Save evgeni/4770573 to your computer and use it in GitHub Desktop.
Save evgeni/4770573 to your computer and use it in GitHub Desktop.
import M2Crypto
import base64
PASS = "secure"
IV = M2Crypto.Rand.rand_bytes(16)
SALT = M2Crypto.Rand.rand_bytes(8)
TEXT = M2Crypto.util.pkcs7_pad("FOO", 16)
c = M2Crypto.EVP.Cipher(alg='aes_128_cbc', key=PASS, iv=IV, op=M2Crypto.encrypt, key_as_bytes=1, salt=SALT)
v = c.update(TEXT)
v = v + c.final()
s = "Salted__"+SALT+IV+v
print base64.b64encode(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment