diff options
| author | Devendra | 2013-02-26 01:02:44 +0530 |
|---|---|---|
| committer | Devendra | 2013-02-26 01:02:44 +0530 |
| commit | 5a47adb56bfe80c34ed5b04a4824e517a3cde16d (patch) | |
| tree | e1471b69edbc249b89313b77b885b6fca3fd2f51 /PubnubCrypto.py | |
| parent | 12aee359893dcdfee2c958ef4c8c98b493b267e6 (diff) | |
| download | pubnub-python-5a47adb56bfe80c34ed5b04a4824e517a3cde16d.tar.bz2 | |
fixiing encryption to interact with php app
Diffstat (limited to 'PubnubCrypto.py')
| -rw-r--r-- | PubnubCrypto.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/PubnubCrypto.py b/PubnubCrypto.py index 744f2d3..b7a57a1 100644 --- a/PubnubCrypto.py +++ b/PubnubCrypto.py @@ -38,7 +38,8 @@ class PubnubCrypto() : #* @return msg with padding. #** """ - return msg + ((block_size - len(msg) % block_size) * chr(block_size - len(msg) % block_size)) + padding = block_size - (len(msg) % block_size) + return msg + chr(padding)*padding def depad( self, msg ): """ @@ -60,7 +61,7 @@ class PubnubCrypto() : #* @return key in MD5 format #** """ - return MD5.new(key).digest() + return hashlib.sha256(key).hexdigest() def encrypt( self, key, msg ): """ @@ -73,9 +74,9 @@ class PubnubCrypto() : """ secret = self.getSecret(key) Initial16bytes='0123456789012345' - cipher = AES.new(secret,AES.MODE_CBC,Initial16bytes) - return encodestring(cipher.encrypt(self.pad(msg))) - + cipher = AES.new(secret[0:32],AES.MODE_CBC,Initial16bytes) + enc = encodestring(cipher.encrypt(self.pad(msg))) + return enc def decrypt( self, key, msg ): """ #** @@ -87,6 +88,6 @@ class PubnubCrypto() : """ secret = self.getSecret(key) Initial16bytes='0123456789012345' - cipher = AES.new(secret,AES.MODE_CBC,Initial16bytes) + cipher = AES.new(secret[0:32],AES.MODE_CBC,Initial16bytes) return self.depad((cipher.decrypt(decodestring(msg)))) |
