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 | |
| parent | 12aee359893dcdfee2c958ef4c8c98b493b267e6 (diff) | |
| download | pubnub-python-5a47adb56bfe80c34ed5b04a4824e517a3cde16d.tar.bz2 | |
fixiing encryption to interact with php app
| -rw-r--r-- | PubnubBase.py | 4 | ||||
| -rw-r--r-- | PubnubCrypto.py | 13 | ||||
| -rw-r--r-- | python-tornado/Pubnub.py | 1 | 
3 files changed, 11 insertions, 7 deletions
| diff --git a/PubnubBase.py b/PubnubBase.py index 074b891..07dd27f 100644 --- a/PubnubBase.py +++ b/PubnubBase.py @@ -16,6 +16,7 @@ import time  import hashlib  import urllib2  import uuid  +from PubnubCrypto import PubnubCrypto  class PubnubBase(object):      def __init__( @@ -95,7 +96,7 @@ class PubnubBase(object):                      out.append(outdict)                  message = json.dumps(out[0])              else: -                message = json.dumps(pc.encrypt(self.cipher_key, message).replace('\n','')) +                message = json.dumps(pc.encrypt(self.cipher_key, json.dumps(message)).replace('\n',''))          else :              message = json.dumps(message) @@ -103,6 +104,7 @@ class PubnubBase(object):      def decrypt(self, message):          if self.cipher_key: +            pc = PubnubCrypto()              if type( message ) == type(list()):                  for item in message:                      encryptItem = pc.decrypt(self.cipher_key, item ) 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)))) diff --git a/python-tornado/Pubnub.py b/python-tornado/Pubnub.py index 880e396..eba2a0f 100644 --- a/python-tornado/Pubnub.py +++ b/python-tornado/Pubnub.py @@ -51,6 +51,7 @@ class Pubnub(PubnubCoreAsync):              publish_key=publish_key,              subscribe_key=subscribe_key,              secret_key=secret_key, +            cipher_key=cipher_key,              ssl_on=ssl_on,              origin=origin,          )         | 
