Hello I am trying to decrypt using AES 128-bit key.
I have key dat file and encrypt dat file, and the ouput is decrypt file.
the error appers
Exception in thread "main" javax.crypto.BadPaddingException: Given final block not properly padded
You seem to be treating encrypted data as text data (by storing it in a String) - that doesn't work. Encrypted data is binary, you need to keep it in a byte.
Rule of thumb (which applies to all Java code, not just encryption code): using "String.getBytes()" and "new String(byte)" is an indicator of looming problems - you should generally specify the encoding.
Ping & DNS - updated with new look and Ping home screen widget
I'm not sure what you mean by "convert data file to string" - if it means you have a file of encrypted data, and that's what you pass off as a string in line 2 - then yes, that's a problem. Encrypted data is binary, not character data, so you need to treat it as such.
Joined: Mar 07, 2013
Thanks A lot for your help,
OK how I can read .dat file?
because I read .dat file, then store in String after that pass as string
I don't know how I can deal with this type of file,
can you help me
Joined: Mar 22, 2005
Assuming that that file contains encrypted data: there is no way you can store its contents in a string. Seriously, until you understand why encrypted data is binary data and not character data -and how both kinds differ- you need to stop working on this project, because you won't get anywhere.
Reading the binary file is simple -- just use the java io library to read the binary data directly into a byte array.
Reem aa wrote:then store in String after that pass as string
As others have already mentioned ... This is the part that breaks. Encrypted data can't be stored into a string (unless you happen to get real lucky and run into a case that does). So, this means that the code that you shown so far is broken. It is not possible to create a string that can be converted back to encrypted data for most of the cases.
In other words, it doesn't matter what you do to convert the string to be passed to the method, the method won't work regardless of what you pass. You need to fix the method before you can worry about passing data to it. Either convert the method to use a byte array instead, or (if you really want to only use a string) convert the method to use a string that is holding encoded data.