python + php encrypt/decrypt

miamia peterirbizon at gmail.com
Mon Jun 6 18:19:11 EDT 2011


On Jun 6, 7:41 pm, geremy condra <debat... at gmail.com> wrote:
> On Sun, Jun 5, 2011 at 3:34 AM, Peter Irbizon <peterirbi... at gmail.com> wrote:
> > Hello, thanks, Unfortunatelly I don't understand how xml should resolve my
> > issue. My problem is:
> > I am trying to use aes256 cbc on python and php to decrypt "textstring". But
> > results are not the same in php and python. Any idea why? password and iv is
> > the same so I don't know where is the problem. I am trying do decrypt data
> > in python then store it as base64 and read and decrypt it in php.
>
> > 2011/6/4 <hid... at gmail.com>
>
> >> Use xml to pass the encrypt text.
>
> >> On , Peter Irbizon <peterirbi... at gmail.com> wrote:
>
Hello,

php I am trying to use is here:
http://code.google.com/p/antares4pymes/source/browse/trunk/library/System/Crypt/AES.php?r=20

and python code:
# -*- coding: utf-8 -*-
from Crypto.Cipher import AES
import base64
import os

BLOCK_SIZE = 32
PADDING = '{'
pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING
EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s)))
DecodeAES = lambda c, e:
c.decrypt(base64.b64decode(e)).rstrip(PADDING)
secret = "passkeypasskeyaa" #os.urandom(BLOCK_SIZE)
iv='1234567890123456'
cipher = AES.new(secret, AES.MODE_CBC, iv)
# encode a string
tajnytext ='Alice has a cat'
encoded = EncodeAES(cipher, tajnytext)
print encoded

# decode the encoded string
decoded = DecodeAES(cipher, encoded)
print 'Decrypted string:', decoded


Thank you for your help in advance

> >> > Hello,
>
> >> > I would like to encrypt text in python and decrypt it in my PHP script.
> >> > I tried to use pycrypto and some aes php scripts but the results are not the
> >> > same. Please, is there any example (the best way source codes) how to do
> >> > this in python and PHP?
>
> Please provide links to the AES implementation you're trying to use
> from PHP and the Python and PHP code you're using.
>
> Geremy Condra- Hide quoted text -
>
> - Show quoted text -




More information about the Python-list mailing list