/** * Construct a private key from its Base58 representation. * @param params * The expected NetworkParameters or null if you don't want validation. * @param base58 * The textual form of the private key. * @throws AddressFormatException * if the given base58 doesn't parse or the checksum is invalid * @throws WrongNetworkException * if the given private key is valid but for a different chain (eg testnet vs mainnet) */ public static DumpedPrivateKey fromBase58(@Nullable NetworkParameters params,String base58) throws AddressFormatException { return new DumpedPrivateKey(params, base58); }
/** * Construct a private key from its Base58 representation. * @param params * The expected NetworkParameters or null if you don't want validation. * @param base58 * The textual form of the private key. * @throws AddressFormatException * if the given base58 doesn't parse or the checksum is invalid * @throws WrongNetworkException * if the given private key is valid but for a different chain (eg testnet vs mainnet) */ public static DumpedPrivateKey fromBase58(@Nullable NetworkParameters params,String base58) throws AddressFormatException { return new DumpedPrivateKey(params, base58); }
/** * Construct a private key from its Base58 representation. * @param params * The expected NetworkParameters or null if you don't want validation. * @param base58 * The textual form of the private key. * @throws AddressFormatException * if the given base58 doesn't parse or the checksum is invalid * @throws WrongNetworkException * if the given private key is valid but for a different chain (eg testnet vs mainnet) */ public static DumpedPrivateKey fromBase58(@Nullable NetworkParameters params,String base58) throws AddressFormatException { return new DumpedPrivateKey(params, base58); }
/** * Construct a private key from its Base58 representation. * @param params * The expected NetworkParameters or null if you don't want validation. * @param base58 * The textual form of the private key. * @throws AddressFormatException * if the given base58 doesn't parse or the checksum is invalid * @throws WrongNetworkException * if the given private key is valid but for a different chain (eg testnet vs mainnet) */ public static DumpedPrivateKey fromBase58(@Nullable NetworkParameters params,String base58) throws AddressFormatException { return new DumpedPrivateKey(params, base58); }
/** * Exports the private key in the form used by Bitcoin Core's "dumpprivkey" and "importprivkey" commands. Use * the {@link org.bitcoinj.core.DumpedPrivateKey#toString()} method to get the string. * * @param params The network this key is intended for use on. * @return Private key bytes as a {@link DumpedPrivateKey}. * @throws IllegalStateException if the private key is not available. */ public DumpedPrivateKey getPrivateKeyEncoded(NetworkParameters params) { return new DumpedPrivateKey(params, getPrivKeyBytes(), isCompressed()); }
/** * Exports the private key in the form used by Bitcoin Core's "dumpprivkey" and "importprivkey" commands. Use * the {@link org.bitcoinj.core.DumpedPrivateKey#toString()} method to get the string. * * @param params The network this key is intended for use on. * @return Private key bytes as a {@link DumpedPrivateKey}. * @throws IllegalStateException if the private key is not available. */ public DumpedPrivateKey getPrivateKeyEncoded(NetworkParameters params) { return new DumpedPrivateKey(params, getPrivKeyBytes(), isCompressed()); }
/** * Exports the private key in the form used by Bitcoin Core's "dumpprivkey" and "importprivkey" commands. Use * the {@link org.bitcoinj.core.DumpedPrivateKey#toString()} method to get the string. * * @param params The network this key is intended for use on. * @return Private key bytes as a {@link DumpedPrivateKey}. * @throws IllegalStateException if the private key is not available. */ public DumpedPrivateKey getPrivateKeyEncoded(NetworkParameters params) { return new DumpedPrivateKey(params, getPrivKeyBytes(), isCompressed()); }
/** * Exports the private key in the form used by Bitcoin Core's "dumpprivkey" and "importprivkey" commands. Use * the {@link org.bitcoinj.core.DumpedPrivateKey#toString()} method to get the string. * * @param params The network this key is intended for use on. * @return Private key bytes as a {@link DumpedPrivateKey}. * @throws IllegalStateException if the private key is not available. */ public DumpedPrivateKey getPrivateKeyEncoded(NetworkParameters params) { return new DumpedPrivateKey(params, getPrivKeyBytes(), isCompressed()); }
@Test public void testJavaSerialization() throws Exception { DumpedPrivateKey key = new DumpedPrivateKey(MAINNET, new ECKey().getPrivKeyBytes(), true); ByteArrayOutputStream os = new ByteArrayOutputStream(); new ObjectOutputStream(os).writeObject(key); DumpedPrivateKey keyCopy = (DumpedPrivateKey) new ObjectInputStream(new ByteArrayInputStream(os.toByteArray())) .readObject(); assertEquals(key, keyCopy); }
@Test public void cloning() throws Exception { DumpedPrivateKey a = new DumpedPrivateKey(MAINNET, new ECKey().getPrivKeyBytes(), true); // TODO: Consider overriding clone() in DumpedPrivateKey to narrow the type DumpedPrivateKey b = (DumpedPrivateKey) a.clone(); assertEquals(a, b); assertNotSame(a, b); }