From 34a1fa996dbdda3410fb25b9f2faeee3b0acf650 Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Wed, 28 Oct 2020 17:35:41 +0100 Subject: [PATCH] Fixed array comparisons / toString with hex --- src/main/java/Main/Commitment.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/Main/Commitment.java b/src/main/java/Main/Commitment.java index f6477f1..802367c 100644 --- a/src/main/java/Main/Commitment.java +++ b/src/main/java/Main/Commitment.java @@ -32,9 +32,9 @@ public class Commitment { this.message = message; this.sequenceA = generateRandomSequence(); - logger.log(Level.INFO, "Random sequence A is " + Arrays.toString(this.sequenceA)); + logger.log(Level.INFO, "Random sequence A is " + Utils.bytesToHex(this.sequenceA)); this.sequenceB = generateRandomSequence(); - logger.log(Level.INFO, "Random sequence B is " + Arrays.toString(this.sequenceB)); + logger.log(Level.INFO, "Random sequence B is " + Utils.bytesToHex(this.sequenceB)); try { MessageDigest digest = MessageDigest.getInstance("SHA-256"); @@ -43,7 +43,7 @@ public class Commitment { digest.update(this.message.getBytes(StandardCharsets.UTF_8)); this.hash = digest.digest(); - logger.log(Level.INFO, "Hash is " + Arrays.toString(this.hash)); + logger.log(Level.INFO, "Hash is " + Utils.bytesToHex(this.hash)); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } @@ -62,7 +62,7 @@ public class Commitment { digest.update(this.sequenceB); digest.update(this.message.getBytes(StandardCharsets.UTF_8)); - result = this.hash == digest.digest(); + result = Arrays.equals(this.hash, digest.digest()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); }