I have this Java code
byte[] decoded= Base64.getDecoder().decode(str.getBytes(StandardCharsets.UTF_8));
byte[] copyfrom12= Arrays.copyOfRange(decoded, 0, Integer.parseInt("12"));
SecretKeySpec secretkeyspec= new SecretKeySpec("0123456789012345".getBytes(), "AES");
Cipher cipher= Cipher.getInstance("AES/GCM/NoPadding");
cipher.init(2, secretkeyspec, new GCMParameterSpec(Integer.parseInt("16") * 8, copyfrom12));
return new String(cipher.doFinal(decoded, Integer.parseInt("12"), decoded.length - Integer.parseInt("12")),StandardCharsets.UTF_8);
I thought the above Java code is self-explanatory, it is only opinion ask me if not please
I tried converting to Python, and this is what I tried, but I don't get the expected decrypted output, instead only bytes using the library PyCryptodome and I am getting this error:
ValueError: MAC check failed
key = b'0123456789012345'
cipher = AES.new(key.encode("utf8"), AES.MODE_GCM, nonce=decoded[:12])
plaintext = cipher.decrypt_and_verify(v5,v5[-16:])
print("plaintext: ", plaintext
The plaintext
does not contain the expected decrypted value. What am I missing here? Is my conversion is still incomplete? Or am I missing some part?
In the comments, a person says it should be sliced in IV|ciphertext|tag
like this, but how can I slice into this?