From b5672601890583a6e1a82b9a48526b5545388d81 Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Sat, 6 Apr 2019 10:32:05 +0200 Subject: [PATCH] ECKey: Decrypted keys must always be 32 bytes long, otherwise likely the encryption key was wrong. --- core/src/main/java/org/bitcoinj/core/ECKey.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/src/main/java/org/bitcoinj/core/ECKey.java b/core/src/main/java/org/bitcoinj/core/ECKey.java index b0ea7715..a686a510 100644 --- a/core/src/main/java/org/bitcoinj/core/ECKey.java +++ b/core/src/main/java/org/bitcoinj/core/ECKey.java @@ -1107,6 +1107,9 @@ public class ECKey implements EncryptableItem { throw new KeyCrypterException("The keyCrypter being used to decrypt the key is different to the one that was used to encrypt it"); checkState(encryptedPrivateKey != null, "This key is not encrypted"); byte[] unencryptedPrivateKey = keyCrypter.decrypt(encryptedPrivateKey, aesKey); + if (unencryptedPrivateKey.length != 32) + throw new KeyCrypterException.InvalidCipherText( + "Decrypted key must be 32 bytes long, but is " + unencryptedPrivateKey.length); ECKey key = ECKey.fromPrivate(unencryptedPrivateKey); if (!isCompressed()) key = key.decompress();