instead of bArr[i2] = num
What's the output then?
Finfally solve the problem In java keyInBytes = keyToBytes("7e585aedb1dd597382cf5aaaabfa221d") returned byte array is [126, 88, 90, -19, -79, -35, 89, 115, -126, -49, 90, -86, -85, -6, 34, 29] for each value in this array is signed byte in decimal form in range of -128 to + 127 Note that for each pair of two characters 7e 58 5a ed ..... For example, it's converted with Interger.parseInt("ed",16) == int('ed',16) == 237 So, the represented 32 bits signed integer in both Python and Java, they are same But In Java, when the integer 237 was converted to byte, it's by default masked to 237 - 256 = -19 if num > 127: num = num - 256 In Python side ,even substract by 256 and got corresponding masked value -19, it's still a 32 bits singed integer not a signed byte. Solution: key = "7e585aedb1dd597382cf5aaaabfa221d" text = 'hello world' ciphter = AESChiper(key) ret = ciphter.encrypt(text) print(ret) def __init__(self, key): self.bs = 16 self.key = unhexlify(key) ## b'~XZ\xed\xb1\xddYs\x82\xcfZ\xaa\xab\xfa"\x1d' self.keyInHexString = b2a_hex(self.key) ## b'7e585aedb1dd597382cf5aaaabfa221d' def encrypt(self, message): message = self._pad(message) iv = unhexlify('0'*32) cipher = AES.new(self.key, AES.MODE_CBC, iv) return base64.b64encode(cipher.encrypt(message)).decode('utf-8') 64 in hex. Correspondingly, in decimal forms are
the problem is here, return base64.b64encode(iv + cipher.encrypt(message)).decode('utf-8')
Обсуждают сегодня