/** * Deserialize a base-58-encoded HD Key. * * @param parent The parent node in the given key's deterministic hierarchy. */ public static DeterministicKey deserializeB58( @Nullable DeterministicKey parent, String base58, NetworkParameters params) { try { return deserialize(params, Base58.decodeChecked(base58), parent); } catch (AddressFormatException e) { throw new IllegalArgumentException(e); } }
public SecretBox(byte[] seed) { checkLength(seed, SEED_LENGTH); this.seed = seed; this.secretKey = CryptoUtils.zeros(SECRETKEY_BYTES * 2); byte[] publicKey = CryptoUtils.zeros(PUBLICKEY_BYTES); isValid( sodium().crypto_sign_ed25519_seed_keypair(publicKey, secretKey, seed), "Failed to generate a key pair"); this.pubKey = Base58.encode(publicKey); }
/** * Attempts to parse the given string as arbitrary-length hex or base58 and then return the * results, or null if neither parse was successful. */ public static byte[] parseAsHexOrBase58(String data) { try { return HEX.decode(data); } catch (Exception e) { // Didn't decode as hex, try base58. try { return Base58.decodeChecked(data); } catch (AddressFormatException e1) { return null; } } }
public static byte[] wifToPrivateKey(String string) { String wif = string; byte[] wif_enc = new byte[wif.length()]; wif_enc = Base58.decode(wif); byte[] wif_enc_fin = new byte[wif_enc.length - 5]; // Drop first and last four bytes System.arraycopy(wif_enc, 1, wif_enc_fin, 0, wif_enc.length - 5); return (wif_enc_fin); }
public static byte[] wifChecksum(String string) { byte[] wif_enc = Base58.decode(string); byte[] wif_enc_sh = new byte[wif_enc.length - 4]; System.arraycopy(wif_enc, 0, wif_enc_sh, 0, wif_enc.length - 4); byte[] hash = new byte[256]; byte[] hash2 = new byte[256]; try { MessageDigest digest = MessageDigest.getInstance("SHA-256"); hash = digest.digest(wif_enc_sh); hash2 = digest.digest(hash); } catch (Exception e) { // TODO: handle exception } byte[] checksum = new byte[4]; System.arraycopy(hash2, 0, checksum, 0, checksum.length); return (checksum); }
/** * Return the secret key, encode in Base58 * * @return */ public String getSecretKey() { return Base58.encode(secretKey); }
static String toBase58(byte[] ser) { return Base58.encode(addChecksum(ser)); }