0

I am using the following code to compute the message digest of a file -
in points to a file here

        bytesRead = in.read(inputBuffer);

         md= MessageDigest.getInstance("SHA3-256");
    while (bytesRead > 0) {
                md.update(inputBuffer, 0, bytesRead);
                    bytesRead = in.read(inputBuffer);
}

Now my aim is to calculate the digest of a file prefixed with a shared secret = hello world
I am not sure if message digest provides any special methods to include a shared secret
I explored the PBEKEYSpec class but that seems to be having a different purpose for passwords etc.
One option to achieve this could be simply to take the shared secret and put it in front of the file and compute the digest. Will that be a good approach? Any other better approach?

sunny
  • 149
  • 8
  • 2
    No need to prefix the file. Just feed the secret into the digest before you feed in the file. – Robby Cornelissen Aug 27 '21 at 10:03
  • Thanks. Separately what's the benefit of including a shared secret key like this. One benefit I could think of is it could prevent pre-image attacks. – sunny Aug 27 '21 at 11:10

0 Answers0