public static byte[] binToNibblesNoTerminator(byte[] str) { byte[] hexEncoded = encode(str); for (int i = 0; i < hexEncoded.length; ++i){ byte b = hexEncoded[i]; hexEncoded[i] = hexMap.get((char) b); } return hexEncoded; } }
/** * Transforms a binary array to hexadecimal format + terminator * * @param str byte[] * @return array with each individual nibble adding a terminator at the end */ public static byte[] binToNibbles(byte[] str) { byte[] hexEncoded = encode(str); byte[] hexEncodedTerminated = Arrays.copyOf(hexEncoded, hexEncoded.length + 1); for (int i = 0; i < hexEncoded.length; ++i){ byte b = hexEncodedTerminated[i]; hexEncodedTerminated[i] = hexMap.get((char) b); } hexEncodedTerminated[hexEncodedTerminated.length - 1] = TERMINATOR; return hexEncodedTerminated; }
@Test public void testAddressStringToBytes() { // valid address String HexStr = "6c386a4b26f73c802f34673f7248bb118f97424a"; byte[] expected = Hex.decode(HexStr); byte[] result = Utils.addressStringToBytes(HexStr); assertEquals(Arrays.areEqual(expected, result), true); // invalid address, we removed the last char so it cannot decode HexStr = "6c386a4b26f73c802f34673f7248bb118f97424"; expected = null; result = Utils.addressStringToBytes(HexStr); assertEquals(expected, result); // invalid address, longer than 20 bytes HexStr = new String(Hex.encode("I am longer than 20 bytes, i promise".getBytes())); expected = null; result = Utils.addressStringToBytes(HexStr); assertEquals(expected, result); // invalid address, shorter than 20 bytes HexStr = new String(Hex.encode("I am short".getBytes())); expected = null; result = Utils.addressStringToBytes(HexStr); assertEquals(expected, result); }
/** * encode the input data producing a Hex encoded byte array. * * @return a byte array containing the Hex encoded data. */ public static byte[] encode( byte[] data) { return encode(data, 0, data.length); }
/** * encode the input data producing a Hex encoded byte array. * * @return a byte array containing the Hex encoded data. */ public static byte[] encode( byte[] data) { return encode(data, 0, data.length); }
public static byte[] binToNibblesNoTerminator(byte[] str) { byte[] hexEncoded = encode(str); for (int i = 0; i < hexEncoded.length; ++i) { byte b = hexEncoded[i]; hexEncoded[i] = hexMap.get((char) b); } return hexEncoded; } }
public static byte[] binToNibblesNoTerminator(byte[] str) { byte[] hexEncoded = encode(str); for (int i = 0; i < hexEncoded.length; ++i) { byte b = hexEncoded[i]; hexEncoded[i] = hexMap.get((char) b); } return hexEncoded; } }
public static byte[] binToNibblesNoTerminator(byte[] str) { byte[] hexEncoded = encode(str); for (int i = 0; i < hexEncoded.length; ++i) { byte b = hexEncoded[i]; hexEncoded[i] = hexMap.get((char) b); } return hexEncoded; } }
public String toString() { return "#"+new String(Hex.encode(string)); } }
public static byte[] binToNibblesNoTerminator(byte[] str) { byte[] hexEncoded = encode(str); for (int i = 0; i < hexEncoded.length; ++i){ byte b = hexEncoded[i]; hexEncoded[i] = hexMap.get((char) b); } return hexEncoded; } }
@Override public String toString() { if (hash == null) return null; return new String(Hex.encode(hash)); }
/** * Transforms a binary array to hexadecimal format + terminator * * @param str byte[] * @return array with each individual nibble adding a terminator at the end */ public static byte[] binToNibbles(byte[] str) { byte[] hexEncoded = encode(str); byte[] hexEncodedTerminated = Arrays.copyOf(hexEncoded, hexEncoded.length + 1); for (int i = 0; i < hexEncoded.length; ++i) { byte b = hexEncodedTerminated[i]; hexEncodedTerminated[i] = hexMap.get((char) b); } hexEncodedTerminated[hexEncodedTerminated.length - 1] = TERMINATOR; return hexEncodedTerminated; }
/** * Transforms a binary array to hexadecimal format + terminator * * @param str byte[] * @return array with each individual nibble adding a terminator at the end */ public static byte[] binToNibbles(byte[] str) { byte[] hexEncoded = encode(str); byte[] hexEncodedTerminated = Arrays.copyOf(hexEncoded, hexEncoded.length + 1); for (int i = 0; i < hexEncoded.length; ++i) { byte b = hexEncodedTerminated[i]; hexEncodedTerminated[i] = hexMap.get((char) b); } hexEncodedTerminated[hexEncodedTerminated.length - 1] = TERMINATOR; return hexEncodedTerminated; }
public String toString() { return "#"+ Strings.fromByteArray(Hex.encode(string)); } }
@Override public String toString() { return MessageFormat.format("ExtendedHierarchicKey[pub: {0}]", new String(Hex.encode(getPubKeyBytes()))); } }
public String getPrivateKey(){ return new String(Hex.encode(getKey())); }
public String getPublicKey(){ return new String(Hex.encode(getKey())); } }
public static String toHexString( byte[] data, int off, int length) { byte[] encoded = encode(data, off, length); return Strings.fromByteArray(encoded); }
public Pair encryptAndWrapPayload(String password) throws JsonProcessingException, UnsupportedEncodingException, EncryptionException, NoSuchAlgorithmException { int iterations = walletBody.getOptions().getPbkdf2Iterations(); String encryptedPayload = AESUtil.encrypt(walletBody.toJson(), password, iterations); WalletWrapper wrapperBody = WalletWrapper.wrap(encryptedPayload, iterations); String checkSum = new String(Hex.encode(MessageDigest.getInstance("SHA-256").digest(wrapperBody.toJson().getBytes("UTF-8")))); return Pair.of(checkSum, wrapperBody); }
public static synchronized Call<ResponseBody> publishTransaction(Transaction transaction, String apiCode) throws IOException { log.info("Publishing transaction"); PushTx pushTx = new PushTx(BlockchainFramework.getRetrofitExplorerInstance(), apiCode); return pushTx.pushTx(new String(Hex.encode(transaction.bitcoinSerialize()))); } }