ECKey: Decrypted keys must always be 32 bytes long, otherwise likely the encryption key was wrong.

This commit is contained in:
Andreas Schildbach
2019-04-06 10:32:05 +02:00
parent c509cdbd95
commit b567260189

View File

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