org.spongycastle.crypto.digests.RIPEMD160Digest Java Examples
The following examples show how to use
org.spongycastle.crypto.digests.RIPEMD160Digest.
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: EOSSign.java From token-core-android with Apache License 2.0 | 7 votes |
private static String serialEOSSignature(byte[] data) { byte[] toHash = ByteUtil.concat(data, "K1".getBytes()); RIPEMD160Digest digest = new RIPEMD160Digest(); digest.update(toHash, 0, toHash.length); byte[] out = new byte[20]; digest.doFinal(out, 0); byte[] checksumBytes = Arrays.copyOfRange(out, 0, 4); data = ByteUtil.concat(data, checksumBytes); return "SIG_K1_" + Base58.encode(data); }
Example #2
Source File: types.java From AndroidWallet with GNU General Public License v3.0 | 6 votes |
@Override public String toString() { RIPEMD160Digest dig = new RIPEMD160Digest(); dig.update(key_data, 0, key_data.length); byte[] out = new byte[20]; dig.doFinal(out, 0); byte[] byteKeyData = new byte[37]; System.arraycopy(key_data, 0, byteKeyData, 0, key_data.length); System.arraycopy(out, 0, byteKeyData, key_data.length, byteKeyData.length - key_data.length); String strResult = GRAPHENE_ADDRESS_PREFIX; strResult += Base58.encode(byteKeyData); return strResult; }
Example #3
Source File: types.java From AndroidWallet with GNU General Public License v3.0 | 6 votes |
public public_key_type(String strBase58) throws NoSuchAlgorithmException { String strPrefix = GRAPHENE_ADDRESS_PREFIX; byte[] byteKeyData = Base58.decode(strBase58.substring(strPrefix.length())); binary_key binaryKey = new binary_key(byteKeyData); RIPEMD160Digest digest = new RIPEMD160Digest(); digest.update(binaryKey.data, 0, binaryKey.data.length); byte[] out = new byte[20]; digest.doFinal(out, 0); byte[] byteOut = new byte[4]; System.arraycopy(out, 0, byteOut, 0, byteOut.length); int nByteOut = ByteBuffer.wrap(byteOut).getInt(); if (nByteOut != binaryKey.check) { throw new RuntimeException("Public key is not valid"); } key_data = binaryKey.data; }
Example #4
Source File: Tools.java From thundernetwork with GNU Affero General Public License v3.0 | 6 votes |
/** * Hash.java secret. * * @param secret the secret * @return the string * @throws UnsupportedEncodingException the unsupported encoding exception * @throws NoSuchAlgorithmException the no such algorithm exception */ public static String hashSecretToString (byte[] secret) { try { MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(secret); byte[] digest = md.digest(); RIPEMD160Digest dig = new RIPEMD160Digest(); dig.update(digest, 0, digest.length); byte[] out = new byte[20]; dig.doFinal(out, 0); return Tools.byteToString(out); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } }
Example #5
Source File: Tools.java From thundernetwork with GNU Affero General Public License v3.0 | 6 votes |
public static byte[] hashSecret (byte[] secret) { try { MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(secret); byte[] digest = md.digest(); RIPEMD160Digest dig = new RIPEMD160Digest(); dig.update(digest, 0, digest.length); byte[] out = new byte[20]; dig.doFinal(out, 0); return out; } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } }
Example #6
Source File: EOSWalletTest.java From token-core-android with Apache License 2.0 | 6 votes |
@Test public void generatePrvPubKey() { byte[] prvWIF = Base58.decode(WIF); // have omitted the checksum verification prvWIF = Arrays.copyOfRange(prvWIF, 1, prvWIF.length - 4); // use the privateKey to calculate the compressed public key directly ECKey ecKey = ECKey.fromPrivate(new BigInteger(1, prvWIF)); byte[] pubKeyData = ecKey.getPubKey(); RIPEMD160Digest digest = new RIPEMD160Digest(); digest.update(pubKeyData, 0, pubKeyData.length); byte[] out = new byte[20]; digest.doFinal(out, 0); byte[] checksumBytes = Arrays.copyOfRange(out, 0, 4); pubKeyData = ByteUtil.concat(pubKeyData, checksumBytes); String eosPK = "EOS" + Base58.encode(pubKeyData); Assert.assertEquals(PUBLIC_KEY, eosPK); }
Example #7
Source File: Tools.java From thunder with GNU Affero General Public License v3.0 | 6 votes |
public static String hashSecretToString (byte[] secret) { try { MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(secret); byte[] digest = md.digest(); RIPEMD160Digest dig = new RIPEMD160Digest(); dig.update(digest, 0, digest.length); byte[] out = new byte[20]; dig.doFinal(out, 0); return Tools.byteToString(out); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } }
Example #8
Source File: Tools.java From thunder with GNU Affero General Public License v3.0 | 6 votes |
public static byte[] hashSecret (byte[] secret) { try { MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(secret); byte[] digest = md.digest(); RIPEMD160Digest dig = new RIPEMD160Digest(); dig.update(digest, 0, digest.length); byte[] out = new byte[20]; dig.doFinal(out, 0); return out; } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } }
Example #9
Source File: types.java From bitshares_wallet with MIT License | 6 votes |
public public_key_type(String strBase58) throws NoSuchAlgorithmException { String strPrefix = GRAPHENE_ADDRESS_PREFIX; byte[] byteKeyData = Base58.decode(strBase58.substring(strPrefix.length())); binary_key binaryKey = new binary_key(byteKeyData); RIPEMD160Digest digest = new RIPEMD160Digest(); digest.update(binaryKey.data, 0, binaryKey.data.length); byte[] out = new byte[20]; digest.doFinal(out, 0); byte[] byteOut = new byte[4]; System.arraycopy(out, 0, byteOut, 0, byteOut.length); int nByteOut = ByteBuffer.wrap(byteOut).getInt(); if (nByteOut != binaryKey.check) { throw new RuntimeException("Public key is not valid"); } key_data = binaryKey.data; }
Example #10
Source File: types.java From guarda-android-wallets with GNU General Public License v3.0 | 6 votes |
@Override public String toString() { RIPEMD160Digest dig = new RIPEMD160Digest(); dig.update(key_data, 0, key_data.length); byte[] out = new byte[20]; dig.doFinal(out, 0); byte[] byteKeyData = new byte[37]; System.arraycopy(key_data, 0, byteKeyData, 0, key_data.length); System.arraycopy(out, 0, byteKeyData, key_data.length, byteKeyData.length - key_data.length); String strResult = GRAPHENE_ADDRESS_PREFIX; strResult += Base58.encode(byteKeyData); return strResult; }
Example #11
Source File: types.java From guarda-android-wallets with GNU General Public License v3.0 | 6 votes |
public public_key_type(String strBase58) throws NoSuchAlgorithmException { String strPrefix = GRAPHENE_ADDRESS_PREFIX; byte[] byteKeyData = Base58.decode(strBase58.substring(strPrefix.length())); binary_key binaryKey = new binary_key(byteKeyData); RIPEMD160Digest digest = new RIPEMD160Digest(); digest.update(binaryKey.data, 0, binaryKey.data.length); byte[] out = new byte[20]; digest.doFinal(out, 0); byte[] byteOut = new byte[4]; System.arraycopy(out, 0, byteOut, 0, byteOut.length); int nByteOut = ByteBuffer.wrap(byteOut).getInt(); if (nByteOut != binaryKey.check) { throw new RuntimeException("Public key is not valid"); } key_data = binaryKey.data; }
Example #12
Source File: types.java From bitshares_wallet with MIT License | 6 votes |
@Override public String toString() { RIPEMD160Digest dig = new RIPEMD160Digest(); dig.update(key_data, 0, key_data.length); byte[] out = new byte[20]; dig.doFinal(out, 0); byte[] byteKeyData = new byte[37]; System.arraycopy(key_data, 0, byteKeyData, 0, key_data.length); System.arraycopy(out, 0, byteKeyData, key_data.length, byteKeyData.length - key_data.length); String strResult = GRAPHENE_ADDRESS_PREFIX; strResult += Base58.encode(byteKeyData); return strResult; }
Example #13
Source File: PublicKey.java From steem-java-api-wrapper with GNU General Public License v3.0 | 5 votes |
/** * Generate the actual checksum of a Steem public key. * * @param publicKey * The public key. * @return The actual checksum of a Steem public key. */ private byte[] calculateChecksum(byte[] publicKey) { RIPEMD160Digest ripemd160Digest = new RIPEMD160Digest(); ripemd160Digest.update(publicKey, 0, publicKey.length); byte[] actualChecksum = new byte[ripemd160Digest.getDigestSize()]; ripemd160Digest.doFinal(actualChecksum, 0); return actualChecksum; }
Example #14
Source File: HashUtil.java From asf-sdk with GNU General Public License v3.0 | 5 votes |
/** * @param data - message to hash * * @return - reipmd160 hash of the message */ public static byte[] ripemd160(byte[] data) { Digest digest = new RIPEMD160Digest(); if (data != null) { byte[] resBuf = new byte[digest.getDigestSize()]; digest.update(data, 0, data.length); digest.doFinal(resBuf, 0); return resBuf; } throw new NullPointerException("Can't hash a NULL value"); }
Example #15
Source File: SerializeUtils.java From nuls with MIT License | 5 votes |
public static byte[] sha256hash160(byte[] input) { byte[] sha256 = Sha256Hash.hash(input); RIPEMD160Digest digest = new RIPEMD160Digest(); digest.update(sha256, 0, sha256.length); byte[] out = new byte[20]; digest.doFinal(out, 0); return out; }
Example #16
Source File: HashUtil.java From nuls with MIT License | 5 votes |
/** * @param data - message to hash * @return - reipmd160 hash of the message */ public static byte[] ripemd160(byte[] data) { Digest digest = new RIPEMD160Digest(); if (data != null) { byte[] resBuf = new byte[digest.getDigestSize()]; digest.update(data, 0, data.length); digest.doFinal(resBuf, 0); return resBuf; } throw new NullPointerException("Can't hash a NULL value"); }
Example #17
Source File: Utils.java From green_android with GNU General Public License v3.0 | 5 votes |
/** * Calculates RIPEMD160(SHA256(input)). This is used in Address calculations. */ public static byte[] sha256hash160(byte[] input) { byte[] sha256 = Sha256Hash.hash(input); RIPEMD160Digest digest = new RIPEMD160Digest(); digest.update(sha256, 0, sha256.length); byte[] out = new byte[20]; digest.doFinal(out, 0); return out; }
Example #18
Source File: Utils.java From GreenBits with GNU General Public License v3.0 | 5 votes |
/** * Calculates RIPEMD160(SHA256(input)). This is used in Address calculations. */ public static byte[] sha256hash160(byte[] input) { byte[] sha256 = Sha256Hash.hash(input); RIPEMD160Digest digest = new RIPEMD160Digest(); digest.update(sha256, 0, sha256.length); byte[] out = new byte[20]; digest.doFinal(out, 0); return out; }
Example #19
Source File: Hash.java From bisq with GNU Affero General Public License v3.0 | 5 votes |
/** * Calculates RIPEMD160(data). */ public static byte[] getRipemd160hash(byte[] data) { RIPEMD160Digest digest = new RIPEMD160Digest(); digest.update(data, 0, data.length); byte[] out = new byte[20]; digest.doFinal(out, 0); return out; }
Example #20
Source File: HashUtils.java From gerbera with MIT License | 5 votes |
public static byte[] ripemd160(byte[] bytes) { RIPEMD160Digest d = new RIPEMD160Digest(); d.update (bytes, 0, bytes.length); byte[] result = new byte[d.getDigestSize()]; d.doFinal(result, 0); return result; }
Example #21
Source File: HashUtil.java From wkcwallet-java with Apache License 2.0 | 5 votes |
/** * @param data - message to hash * @return - reipmd160 hash of the message */ public static byte[] ripemd160(byte[] data) { Digest digest = new RIPEMD160Digest(); if (data != null) { byte[] resBuf = new byte[digest.getDigestSize()]; digest.update(data, 0, data.length); digest.doFinal(resBuf, 0); return resBuf; } throw new NullPointerException("Can't hash a NULL value"); }
Example #22
Source File: EncryptUtils.java From bcm-android with GNU General Public License v3.0 | 5 votes |
/** * Calculates RIPEMD160(SHA256(input)). This is used in Address calculations. */ public static byte[] sha256hash160(byte[] input) { byte[] sha256 = computeSHA256(input); RIPEMD160Digest digest = new RIPEMD160Digest(); digest.update(sha256, 0, sha256.length); byte[] out = new byte[20]; digest.doFinal(out, 0); return out; }
Example #23
Source File: RIPEMD160.java From BlockchainWallet-Crypto with GNU General Public License v3.0 | 5 votes |
public static byte[] ripemd160(byte[] bytes) { RIPEMD160Digest ripemd160Digest = new RIPEMD160Digest(); ripemd160Digest.update(bytes, 0, bytes.length); byte[] hash160 = new byte[RIPEMD160_DIGEST_LENGTH]; ripemd160Digest.doFinal(hash160, 0); return hash160; }
Example #24
Source File: Utils.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
public static byte[] calculateChecksum(byte[] data) { byte[] checksum = new byte[160 / 8]; RIPEMD160Digest ripemd160Digest = new RIPEMD160Digest(); ripemd160Digest.update(data, 0, data.length); ripemd160Digest.doFinal(checksum, 0); return Arrays.copyOfRange(checksum, 0, 4); }
Example #25
Source File: ZCashWalletManager.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
public static String publicKeyFromPrivateKey_taddr(String privKey) throws ZCashException { String methodName = "publicKeyFromPrivateKey_taddr"; checkArgumentNonNull(privKey, "privKey", methodName); try { Base58.decodeChecked(privKey); } catch (IllegalArgumentException e) { throw new ZCashException("Invalid private key."); } ECKey key = DumpedPrivateKey.fromBase58(privKey); byte[] pubKey = key.getPubKeyPoint().getEncoded(key.isCompressed()); pubKey = Sha256Hash.hash(pubKey); byte[] pubKeyHash = new byte[20]; RIPEMD160Digest ripemd160Digest = new RIPEMD160Digest(); ripemd160Digest.update(pubKey, 0, pubKey.length); ripemd160Digest.doFinal(pubKeyHash, 0); pubKey = Bytes.concat(ZEC_MAINNET_ADDR_PREFIX, pubKeyHash); // pubKey = Bytes.concat(ZEC_TESTNET_ADDR_PREFIX, pubKeyHash); // ^~~~~~~~~~~~~~~~~~~~~~~~ mainnet prefix byte[] checksum = Sha256Hash.hashTwice(pubKey); byte[] summed = Bytes.concat(pubKey, new byte[]{checksum[0], checksum[1], checksum[2], checksum[3]}); return Base58.encode(summed); }
Example #26
Source File: Utils.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
public static byte[] calculateChecksum(byte[] data) { byte[] checksum = new byte[160 / 8]; RIPEMD160Digest ripemd160Digest = new RIPEMD160Digest(); ripemd160Digest.update(data, 0, data.length); ripemd160Digest.doFinal(checksum, 0); return Arrays.copyOfRange(checksum, 0, 4); }
Example #27
Source File: ZCashWalletManager.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
public static String publicKeyFromPrivateKey_taddr(String privKey) throws ZCashException { String methodName = "publicKeyFromPrivateKey_taddr"; checkArgumentNonNull(privKey, "privKey", methodName); try { Base58.decodeChecked(privKey); } catch (IllegalArgumentException e) { throw new ZCashException("Invalid private key."); } ECKey key = DumpedPrivateKey.fromBase58(privKey); byte[] pubKey = key.getPubKeyPoint().getEncoded(key.isCompressed()); pubKey = Sha256Hash.hash(pubKey); byte[] pubKeyHash = new byte[20]; RIPEMD160Digest ripemd160Digest = new RIPEMD160Digest(); ripemd160Digest.update(pubKey, 0, pubKey.length); ripemd160Digest.doFinal(pubKeyHash, 0); pubKey = Bytes.concat(ZEC_MAINNET_ADDR_PREFIX, pubKeyHash); // pubKey = Bytes.concat(ZEC_TESTNET_ADDR_PREFIX, pubKeyHash); // ^~~~~~~~~~~~~~~~~~~~~~~~ mainnet prefix byte[] checksum = Sha256Hash.hashTwice(pubKey); byte[] summed = Bytes.concat(pubKey, new byte[]{checksum[0], checksum[1], checksum[2], checksum[3]}); return Base58.encode(summed); }
Example #28
Source File: DecentWalletManager.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
public static String publicKeyFromPrivateKey(String privateKey) { byte[] pubKey = null; try { pubKey = DumpedPrivateKey.fromBase58(privateKey).getPubKeyPoint().getEncoded(true); } catch (Exception e) { return null; } byte[] checksum = new byte[160 / 8]; RIPEMD160Digest ripemd160Digest = new RIPEMD160Digest(); ripemd160Digest.update(pubKey, 0, pubKey.length); ripemd160Digest.doFinal(checksum, 0); checksum = Arrays.copyOfRange(checksum, 0, 4); byte[] pubKeyChecksummed = Bytes.concat(pubKey, checksum); return "DCT" + Base58.encode(pubKeyChecksummed); }
Example #29
Source File: EOSKey.java From token-core-android with Apache License 2.0 | 5 votes |
public String getPublicKeyAsHex() { ECKey ecKey = ECKey.fromPrivate(bytes); byte[] pubKeyData = ecKey.getPubKey(); RIPEMD160Digest digest = new RIPEMD160Digest(); digest.update(pubKeyData, 0, pubKeyData.length); byte[] out = new byte[20]; digest.doFinal(out, 0); byte[] checksumBytes = Arrays.copyOfRange(out, 0, 4); pubKeyData = ByteUtil.concat(pubKeyData, checksumBytes); return "EOS" + Base58.encode(pubKeyData); }
Example #30
Source File: Hash.java From neb.java with GNU Lesser General Public License v3.0 | 5 votes |
public static byte[] Ripemd160(byte[]... args) { RIPEMD160Digest digest = new RIPEMD160Digest(); for (int i = 0; i < args.length; i++) { byte[] bytes = args[i]; digest.update(bytes, 0, bytes.length); } byte[] out = new byte[20]; digest.doFinal(out, 0); return out; }