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

#414 Update moved exception location

parent 7948d210
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.core.crypto;
import de.fitko.fitconnect.api.exceptions.internal.InitializationException;
import de.fitko.fitconnect.api.exceptions.InitializationException;
import java.io.File;
import java.io.IOException;
......@@ -18,8 +18,8 @@ public class HashUtil {
public HashUtil() {
try {
this.messageDigest = MessageDigest.getInstance(DEFAULT_ALGORITHM);
} catch (NoSuchAlgorithmException e) {
throw new InitializationException(e.getMessage(),e);
} catch (final NoSuchAlgorithmException e) {
throw new InitializationException(e.getMessage(), e);
}
}
......@@ -27,26 +27,26 @@ public class HashUtil {
this.messageDigest = messageDigest;
}
public byte[] createHash(byte[] data) {
public byte[] createHash(final byte[] data) {
this.messageDigest.reset();
return this.messageDigest.digest(data);
}
public boolean verify(byte[] originalHash, byte[] data) {
byte[] newHash = createHash(data);
public boolean verify(final byte[] originalHash, final byte[] data) {
final byte[] newHash = createHash(data);
return compareHashes(originalHash, newHash);
}
public String createHashFromFile(File file) throws IOException {
public String createHashFromFile(final File file) throws IOException {
try {
byte[] rawData = Files.readAllBytes(Paths.get(file.getPath()));
final byte[] rawData = Files.readAllBytes(Paths.get(file.getPath()));
return new String(rawData);
} catch (IOException e) {
} catch (final IOException e) {
throw e;
}
}
private boolean compareHashes(byte[] originalHash, byte[] comparisonHash) {
private boolean compareHashes(final byte[] originalHash, final byte[] comparisonHash) {
int diff = originalHash.length ^ comparisonHash.length;
for (int i = 0; i < originalHash.length && i < comparisonHash.length; i++) {
diff |= originalHash[i] ^ comparisonHash[i];
......
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