First I create a signature (byte[] signature). Then I write this signature to the file. I read the signature from this file and give it another variable (byte [] signatureCopy). But when I compare these two variables, it returns false. How can I resolve it?
But when I print the screen, it looks the same.
System.out.println (new String (signature));
System.out.println (new String (signatureCopy));
Code:
byte[] signature = this.signature(data);
FileUtil.writeRegistryFileSigned(path, signature);
byte[] signatureCopy = FileUtil.readSignatureInRegistryFile(path);
System.out.println(Arrays.equals(signature, signatureCopy)); //FALSE
Functions;
public static byte[] readSignatureInRegistryFile(String filePath){
byte[] data = null;
try {
data = Files.readAllBytes(Paths.get(filePath));
} catch (IOException e) {
e.printStackTrace();
}
return data;
}
public static void writeRegistryFileSigned(String filePath, byte[] signature) {
File fileRegistry = new File(filePath);
try {
fileRegistry.createNewFile();
} catch (IOException e1) {
}
try (FileWriter fw = new FileWriter(fileRegistry, true);
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter out = new PrintWriter(bw)) {
out.println(new String(signature));
} catch (IOException e) {
}
}