Java Code Examples for net.bither.bitherj.BitherjSettings#dumpedPrivateKeyHeader()

The following examples show how to use net.bither.bitherj.BitherjSettings#dumpedPrivateKeyHeader() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DumpedPrivateKey.java    From bitherj with Apache License 2.0 6 votes vote down vote up
/**
 * Parses the given private key as created by the "dumpprivkey" Bitcoin C++ RPC.
 *
 * @param encoded The base58 encoded string.
 * @throws net.bither.bitherj.exception.AddressFormatException If the string is invalid or the header byte doesn't match the network params.
 */
public DumpedPrivateKey(String encoded) throws AddressFormatException {
    //todo string encoded
    byte[] tmp = Base58.decodeChecked(encoded);
    version = tmp[0] & 0xFF;
    bytes = new byte[tmp.length - 1];
    System.arraycopy(tmp, 1, bytes, 0, tmp.length - 1);

    if (version != BitherjSettings.dumpedPrivateKeyHeader)
        throw new AddressFormatException("Mismatched version number, trying to cross networks? " + version +
                " vs " + BitherjSettings.dumpedPrivateKeyHeader);
    if (bytes.length == 33 && bytes[32] == 1) {
        compressed = true;
        bytes = Arrays.copyOf(bytes, 32);  // Chop off the additional marker byte.
    } else if (bytes.length == 32) {
        compressed = false;
    } else {
        throw new AddressFormatException("Wrong number of bytes for a private key, not 32 or 33");
    }
}
 
Example 2
Source File: DumpedPrivateKey.java    From bitherj with Apache License 2.0 4 votes vote down vote up
public DumpedPrivateKey(byte[] keyBytes, boolean compressed) {
    version = BitherjSettings.dumpedPrivateKeyHeader;
    bytes = encode(keyBytes, compressed);
    checkArgument(version < 256 && version >= 0);
    this.compressed = compressed;
}