aboutsummaryrefslogtreecommitdiffstats
path: root/common/PubnubCrypto.py
diff options
context:
space:
mode:
Diffstat (limited to 'common/PubnubCrypto.py')
-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')