I'm working on a security application using my own customized cryptography method, and having a problem on message decryption.
According to the theory, the input has to be padded to meet the required bit to execute the encryption. But the padded bits stays even after the decryption.
Here's an example:
input (before padding) : q
input (after padding) : 113 0 0 0 0 0 0 0 (in Bytes)
Then I execute some code:
bytes[] a = encrypt(input);
bytes[] b = decrypt(a);
String output = "";
output = new String(b, "UTF-8");
The output on System.out.println is below:
b : 113 0 0 0 0 0 0 0
output : q[][][][][][][]
I have no idea how to remove the padded bits. I'm currently using the function below:
public String processOutput(String dtxt){
String result = "";
int l = dtxt.length();
for(int i=0;i<l-16;i++) result = result + dtxt.charAt(i);
for(int i=l-16;i<l;i++){
if((long)dtxt.charAt(i)!=0){
result = result + dtxt.charAt(i);
}
} return result;
}
But this function will only works if I put the output to a String. What if the output is a file (let's say an image file)? How to remove the padded bits after decryption? Please help.