aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorDevendra2014-03-25 10:50:39 +0530
committerDevendra2014-03-25 10:50:39 +0530
commitb8d1dd86a0d8c4261d4f3765f3ca227d7b555c84 (patch)
treed5cd2e092f44ff36e739fd029afc7b028c8c087f /common
parent80edcffbfe140a6d19c65deca24e1ba1c0f49b99 (diff)
downloadpubnub-python-b8d1dd86a0d8c4261d4f3765f3ca227d7b555c84.tar.bz2
fixing encryption, and changing from urllib3 to urllib
Diffstat (limited to 'common')
-rw-r--r--common/PubnubCrypto.py9
1 files changed, 4 insertions, 5 deletions
diff --git a/common/PubnubCrypto.py b/common/PubnubCrypto.py
index df7cb8d..1f5fc8d 100644
--- a/common/PubnubCrypto.py
+++ b/common/PubnubCrypto.py
@@ -28,7 +28,7 @@ class PubnubCrypto() :
#**
"""
padding = block_size - (len(msg) % block_size)
- return msg + chr(padding)*padding
+ return msg + (chr(padding)*padding).encode('utf-8')
def depad( self, msg ):
"""
@@ -50,7 +50,7 @@ class PubnubCrypto() :
#* @return key in MD5 format
#**
"""
- return hashlib.sha256(key).hexdigest()
+ return hashlib.sha256(key.encode("utf-8")).hexdigest()
def encrypt( self, key, msg ):
"""
@@ -64,8 +64,7 @@ class PubnubCrypto() :
secret = self.getSecret(key)
Initial16bytes='0123456789012345'
cipher = AES.new(secret[0:32],AES.MODE_CBC,Initial16bytes)
- enc = encodestring(cipher.encrypt(self.pad(msg)))
- return enc
+ return encodestring(cipher.encrypt(self.pad(msg.encode('utf-8')))).decode('utf-8')
def decrypt( self, key, msg ):
"""
#**
@@ -78,4 +77,4 @@ class PubnubCrypto() :
secret = self.getSecret(key)
Initial16bytes='0123456789012345'
cipher = AES.new(secret[0:32],AES.MODE_CBC,Initial16bytes)
- return self.depad((cipher.decrypt(decodestring(msg))))
+ return (cipher.decrypt(decodestring(msg.encode('utf-8')))).decode('utf-8')