From a73677e9fb7c520618cb382be424837c26c905bc Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Wed, 2 Sep 2015 20:09:16 +0200 Subject: [PATCH] DeterministicKey: throw a KeyCrypterException instead of an IllegalStateException if the derivation check fails (as this can happen when the password is wrong) --- core/src/main/java/org/bitcoinj/crypto/DeterministicKey.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/bitcoinj/crypto/DeterministicKey.java b/core/src/main/java/org/bitcoinj/crypto/DeterministicKey.java index 3272f749d..2d2e10a65 100644 --- a/core/src/main/java/org/bitcoinj/crypto/DeterministicKey.java +++ b/core/src/main/java/org/bitcoinj/crypto/DeterministicKey.java @@ -433,7 +433,10 @@ public class DeterministicKey extends ECKey { downCursor = HDKeyDerivation.deriveChildKey(downCursor, num); } // downCursor is now the same key as us, but with private key bytes. - checkState(downCursor.pub.equals(pub)); + // If it's not, it means we tried decrypting with an invalid password and earlier checks e.g. for padding didn't + // catch it. + if (!downCursor.pub.equals(pub)) + throw new KeyCrypterException("Could not decrypt bytes"); return checkNotNull(downCursor.priv); }