From 3dd55f3a32a5498fa770403de62b093c8a632480 Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Wed, 28 Oct 2020 17:25:08 +0100 Subject: [PATCH] Added hash checker / removed redundant setters for safety --- src/main/java/Main/Commitment.java | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main/java/Main/Commitment.java b/src/main/java/Main/Commitment.java index 1fffae1..79ee88a 100644 --- a/src/main/java/Main/Commitment.java +++ b/src/main/java/Main/Commitment.java @@ -52,6 +52,22 @@ public class Commitment { public Commitment() { } + public boolean checkHash() { + boolean result = false; + try { + MessageDigest digest = MessageDigest.getInstance("SHA-256"); + digest.update(this.sequenceA); + digest.update(this.sequenceB); + digest.update(this.message.getBytes(StandardCharsets.UTF_8)); + + result = this.hash == digest.digest(); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } + return result; + } + + public String getMessage() { return message; } @@ -72,15 +88,8 @@ public class Commitment { this.message = message; } - public void setSequenceA(byte[] sequenceA) { - this.sequenceA = sequenceA; - } - public void setSequenceB(byte[] sequenceB) { this.sequenceB = sequenceB; } - public void setHash(byte[] hash) { - this.hash = hash; - } }