@Test public void bip38testvector_test1() throws Exception { BIP38PrivateKey encryptedKey = new BIP38PrivateKey(MAINNET, "6PRNhgoezXcrzkoSwugoo5m9DJvLiGj48Y27RsDnQpMGLH2WGtcsoZM4J6"); ECKey key = encryptedKey.decrypt("TestingOneTwoThree"); assertEquals("7RKVWf9kXjwZMJKrGpBsFwthpukyW6taTonWsmVbCoRQ1LUy4xC", key.getPrivateKeyEncoded(MAINNET) .toString()); }
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.twiceOf(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 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.twiceOf(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 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.twiceOf(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); }
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.twiceOf(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(); }
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.twiceOf(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(); transient NetworkParameters params; final boolean ecMultiply; final boolean compressed; final boolean hasLotAndSequence; final byte[] addressHash; final byte[] content; }