mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-01-31 23:32:16 +00:00
Check that the private key decrypted correctly in ECKey.sign(). Resolves issue 359.
This commit is contained in:
parent
7b8eab19ff
commit
4273dacc00
@ -375,6 +375,9 @@ public class ECKey implements Serializable {
|
||||
}
|
||||
|
||||
privateKeyForSigning = new BigInteger(1, keyCrypter.decrypt(encryptedPrivateKey, aesKey));
|
||||
// Check encryption was correct.
|
||||
if (!Arrays.equals(pub, publicKeyFromPrivate(privateKeyForSigning, isCompressed())))
|
||||
throw new KeyCrypterException("Could not decrypt bytes");
|
||||
} else {
|
||||
// No decryption of private key required.
|
||||
if (priv == null) {
|
||||
|
@ -168,7 +168,14 @@ public class WalletTest {
|
||||
|
||||
@Test
|
||||
public void basicSpendingWithEncryptedHetergeneousWallet() throws Exception {
|
||||
basicSpendingCommon(encryptedHetergeneousWallet, myEncryptedAddress2, true);
|
||||
for (int i = 0; i < 100; i++) {
|
||||
encryptedHetergeneousWallet = new Wallet(params, keyCrypter);
|
||||
myKey2 = new ECKey();
|
||||
encryptedHetergeneousWallet.addKey(myKey2);
|
||||
myEncryptedKey2 = encryptedHetergeneousWallet.addNewEncryptedKey(keyCrypter, aesKey);
|
||||
myEncryptedAddress2 = myEncryptedKey2.toAddress(params);
|
||||
basicSpendingCommon(encryptedHetergeneousWallet, myEncryptedAddress2, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void basicSpendingCommon(Wallet wallet, Address toAddress, boolean testEncryption) throws Exception {
|
||||
|
Loading…
Reference in New Issue
Block a user