EtherSaleWalletDecoder { public byte[] getPrivateKey(final String password) throws InvalidCipherTextException { byte[] passwordHash = generatePasswordHash(password); byte[] decryptedSeed = decryptSeed(passwordHash, etherSaleWallet.getEncseedBytes()); return hashSeed(decryptedSeed); } EtherSaleWalletDecoder(final EtherSaleWallet wallet); byte[] getPrivateKey(final String password); static final int HASH_ITERATIONS; static final int DERIVED_KEY_BIT_COUNT; static final int IV_LENGTH; }
@Test public void shouldGetPrivateKey() throws InvalidCipherTextException { byte[] result = walletDecoder.getPrivateKey("foobar"); String resultString = Hex.toHexString(result); assertThat(resultString.toLowerCase(), is("74ef8a796480dda87b4bc550b94c408ad386af0f65926a392136286784d63858")); }
@Test(expected = InvalidCipherTextException.class) public void shouldRejectWrongPassword() throws InvalidCipherTextException { walletDecoder.getPrivateKey("foo"); }
@Test(expected = InvalidCipherTextException.class) public void shouldRejectWrongPasswordSameLength() throws InvalidCipherTextException { walletDecoder.getPrivateKey("barfoo"); }
@Test public void ethereumAddressShouldMatchPrivateKey() throws InvalidCipherTextException { BigInteger privKey = new BigInteger(walletDecoder.getPrivateKey("foobar")); byte[] addr = ECKey.fromPrivate(privKey).getAddress(); assertThat(Hex.toHexString(etherSaleWallet.getEthaddrBytes()), is(Hex.toHexString(addr))); }
@Test(expected = InvalidCipherTextException.class) public void shouldHandleBrokenWallet() throws IOException, InvalidCipherTextException { EtherSaleWallet brokenEtherSaleWallet = mapper.readValue(getClass().getResourceAsStream("/wallet/ethersalewallet_broken.json"), EtherSaleWallet.class); EtherSaleWalletDecoder walletDecoder = new EtherSaleWalletDecoder(brokenEtherSaleWallet); walletDecoder.getPrivateKey("foobar"); }