DeterministicKey: throw a KeyCrypterException instead of an IllegalStateException if the derivation check fails (as this can happen when the password is wrong)

This commit is contained in:
Mike Hearn 2015-09-02 20:09:16 +02:00
parent 48b4df73a1
commit a73677e9fb

View file

@ -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);
}