problem description
how to use byte array decryption in Python when getting java des encrypted data and key,?
the environmental background of the problems and what methods you have tried
when performing python automated testing, you need to decrypt and compare the data
related codes
/ / Please paste the code text below (do not replace the code with pictures)
< H1 >! / usr/local/bin/python < / H1 > < H1 >--coding: utf-8--< / H1 >from pyDes import *
def desDescrypt ():
print ("Example of DES encryption using CBC mode\n")
key = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
arr = bytearray(key)
k = triple_des(key, CBC, pad=None, padmode=PAD_PKCS5)
data = "DES encryption algorithm"
print ("Key : %r" % k.getKey())
print ("Data : %r" % data)
d = k.encrypt(data)
print ("Encrypted: %r" % d)
if _ _ name__=="__main__":
ss = desDescrypt()
print ss
what result do you expect? What is the error message actually seen?
failed to decrypt, error:
File "D:/pyWorkspace/testPy/pyRRR.py", line 36, in < module >
ss = desid( )
File "D:/pyWorkspace/testPy/pyRRR.py", line 11, in desid
k = triple_des(key, pyDes.CBC, pad=None, padmode=pyDes.PAD_PKCS5)
File "C:Python27libsite-packagespyDes.py", line 710, in init
self.setKey(key)
File "C:Python27libsite-packagespyDes.py", line 727, in setKey
self._padding, self._padmode)
File "C:Python27libsite-packagespyDes.py", line 409, in init
self.setKey(key)
File "C:Python27libsite-packagespyDes.py", line 414, in setKey
self.__create_sub_keys()
File "C:Python27libsite-packagespyDes.py", line 462, in _ create_sub_keys
key = self.__permutate(des.__pc1, self.__String_to_BitList(self.getKey()))
File "C:Python27libsite-packagespyDes.py", line 421, in _ String_to_BitList
data = [ord(c) for c in data]
TypeError: ord () expected string of length 1, but int found