Skip to content
Snippets Groups Projects
Commit 6d015779 authored by Martin Vogel's avatar Martin Vogel
Browse files

#414 Inject hash algorithm

parent 723362fa
No related branches found
No related tags found
2 merge requests!2#414 Remaining changes from MR,!1planning#414 Methoden Signaturen (Zwischenstand)
package de.fitko.fitconnect.impl.crypto;
import de.fitko.fitconnect.api.exceptions.VerificationException;
import de.fitko.fitconnect.api.exceptions.InitializationException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
......@@ -9,19 +9,23 @@ public class MetadataVerifier {
private static final String DEFAULT_ALGORITHM = "SHA-512"; // Currently, only SHA-512 is supported.
private final MessageDigest hasher;
private final MessageDigest messageDigest;
public MetadataVerifier() {
try {
this.hasher = MessageDigest.getInstance(DEFAULT_ALGORITHM);
this.messageDigest = MessageDigest.getInstance(DEFAULT_ALGORITHM);
} catch (NoSuchAlgorithmException e) {
throw new VerificationException(e.getMessage(),e);
throw new InitializationException(e.getMessage(),e);
}
}
public MetadataVerifier(final MessageDigest messageDigest) {
this.messageDigest = messageDigest;
}
public byte[] createHash(byte[] data) {
this.hasher.reset();
return this.hasher.digest(data);
this.messageDigest.reset();
return this.messageDigest.digest(data);
}
public boolean verify(byte[] originalHash, byte[] data) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment