mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-07-30 03:21:23 +00:00
KeyCrypterException: Introduce dedicated InvalidCipherText exception for when a private key or seed is decrypted, the decrypted message is damaged.
This commit is contained in:
@@ -49,4 +49,18 @@ public class KeyCrypterException extends RuntimeException {
|
||||
super(message, throwable);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This exception is thrown when a private key or seed is decrypted, the decrypted message is damaged
|
||||
* (e.g. the padding is damaged). This likely means the wrong decryption key has been used.
|
||||
*/
|
||||
public static class InvalidCipherText extends KeyCrypterException {
|
||||
public InvalidCipherText(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public InvalidCipherText(String message, Throwable throwable) {
|
||||
super(message, throwable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -29,6 +29,7 @@ import org.bouncycastle.crypto.engines.AESEngine;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.bouncycastle.crypto.BufferedBlockCipher;
|
||||
import org.bouncycastle.crypto.InvalidCipherTextException;
|
||||
import org.bouncycastle.crypto.modes.CBCBlockCipher;
|
||||
import org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher;
|
||||
import org.bouncycastle.crypto.params.KeyParameter;
|
||||
@@ -224,7 +225,9 @@ public class KeyCrypterScrypt implements KeyCrypter {
|
||||
final int length2 = cipher.doFinal(decryptedBytes, length1);
|
||||
|
||||
return Arrays.copyOf(decryptedBytes, length1 + length2);
|
||||
} catch (Exception e) {
|
||||
} catch (InvalidCipherTextException e) {
|
||||
throw new KeyCrypterException.InvalidCipherText("Could not decrypt bytes", e);
|
||||
} catch (RuntimeException e) {
|
||||
throw new KeyCrypterException("Could not decrypt bytes", e);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user