### Question:
BIP38PrivateKey extends VersionedChecksummedBytes { public ECKey decrypt(String passphrase) throws BadPassphraseException { String normalizedPassphrase = Normalizer.normalize(passphrase, Normalizer.Form.NFC); ECKey key = ecMultiply ? decryptEC(normalizedPassphrase) : decryptNoEC(normalizedPassphrase); Sha256Hash hash = Sha256Hash.createDouble(key.toAddress(params).toString().getBytes(Charsets.US_ASCII)); byte[] actualAddressHash = Arrays.copyOfRange(hash.getBytes(), 0, 4); if (!Arrays.equals(actualAddressHash, addressHash)) throw new BadPassphraseException(); return key; } BIP38PrivateKey(NetworkParameters params, String encoded); ECKey decrypt(String passphrase); @Override boolean equals(Object o); @Override int hashCode(); final NetworkParameters params; final boolean ecMultiply; final boolean compressed; final boolean hasLotAndSequence; final byte[] addressHash; final byte[] content; }### Answer:
@Test public void bip38testvector_test1() throws Exception { BIP38PrivateKey encryptedKey = new BIP38PrivateKey(MAINNET, "6PfRBdq72gua9HRkZS1X8DJLd8vRi7hbNjUkiauLkThWvd52eMyGmeS7vc"); ECKey key = encryptedKey.decrypt("TestingOneTwoThree"); assertEquals("79mY6oZViLXkGjgD2BDsdP6WVzqEJU9aAhDevZzRFZNJ4My5qcB", key.getPrivateKeyEncoded(MAINNET) .toString()); }
@Test public void bip38testvector_test2() throws Exception { BIP38PrivateKey encryptedKey = new BIP38PrivateKey(MAINNET, "6PfSCRxC8cvNk83vJV7FDSS3HWcyez2bVzc4wqTFFHGMwnaowAjQrDCeA3"); ECKey key = encryptedKey.decrypt("Satoshi"); assertEquals("7AKD3wi1cMKpha7UGGT1LroBZhw55QciLedyqqjUrHhEyfaAqiK", key.getPrivateKeyEncoded(MAINNET) .toString()); }
@Test(expected = BadPassphraseException.class) public void badPassphrase() throws Exception { BIP38PrivateKey encryptedKey = new BIP38PrivateKey(MAINNET, "6PfRBdq72gua9HRkZS1X8DJLd8vRi7hbNjUkiauLkThWvd52eMyGmeS7vc"); encryptedKey.decrypt("BAD"); }