3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-01 07:42:17 +00:00

Check that the private key decrypted correctly in ECKey.sign(). Resolves issue 359.

This commit is contained in:
Mike Hearn 2013-03-29 17:05:39 +00:00
parent 7b8eab19ff
commit 4273dacc00
2 changed files with 11 additions and 1 deletions

View File

@ -375,6 +375,9 @@ public class ECKey implements Serializable {
} }
privateKeyForSigning = new BigInteger(1, keyCrypter.decrypt(encryptedPrivateKey, aesKey)); 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 { } else {
// No decryption of private key required. // No decryption of private key required.
if (priv == null) { if (priv == null) {

View File

@ -168,7 +168,14 @@ public class WalletTest {
@Test @Test
public void basicSpendingWithEncryptedHetergeneousWallet() throws Exception { 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 { private void basicSpendingCommon(Wallet wallet, Address toAddress, boolean testEncryption) throws Exception {