예제 #1
0
 /**
  * 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);
   }
 }
예제 #2
0
 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);
 }
예제 #3
0
 /**
  * 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;
     }
   }
 }
예제 #4
0
파일: Address.java 프로젝트: gitonio/btcJ
  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);
  }
예제 #5
0
파일: Address.java 프로젝트: gitonio/btcJ
  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);
  }
예제 #6
0
 /**
  * Return the secret key, encode in Base58
  *
  * @return
  */
 public String getSecretKey() {
   return Base58.encode(secretKey);
 }
예제 #7
0
 static String toBase58(byte[] ser) {
   return Base58.encode(addChecksum(ser));
 }