本文整理汇总了Java中org.bouncycastle.crypto.digests.RIPEMD160Digest.update方法的典型用法代码示例。如果您正苦于以下问题:Java RIPEMD160Digest.update方法的具体用法?Java RIPEMD160Digest.update怎么用?Java RIPEMD160Digest.update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.crypto.digests.RIPEMD160Digest
的用法示例。
在下文中一共展示了RIPEMD160Digest.update方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createFromUserAttribute
import org.bouncycastle.crypto.digests.RIPEMD160Digest; //导入方法依赖的package包/类
public static PgpUserIdNameHash createFromUserAttribute(final PGPUserAttributeSubpacketVector userAttribute) {
assertNotNull(userAttribute, "userAttribute");
final RIPEMD160Digest digest = new RIPEMD160Digest();
// TODO this needs to be extended, if there is ever any other attribute possible, too!
// Currently, image seems to be the only supported attribute. Alternatively, we could get the data via reflection...
final UserAttributeSubpacket subpacket = userAttribute.getSubpacket(UserAttributeSubpacketTags.IMAGE_ATTRIBUTE);
assertNotNull(subpacket, "subpacket");
final byte[] data = assertNotNull(subpacket.getData(), "subpacket.data");
digest.update(data, 0, data.length);
final byte[] out = new byte[digest.getDigestSize()];
digest.doFinal(out, 0);
return new PgpUserIdNameHash(out);
}
示例2: RIPEMD160
import org.bouncycastle.crypto.digests.RIPEMD160Digest; //导入方法依赖的package包/类
/********
* This method does all the RipeMD 160 hashing function, and after that hash has taken place, it prepends the version
* byte to the beginning of the Byte array
* @param tobeHashed - Byte Array of the public key after a SHA-256 hash
* @return - Byte Array after the RipeMD 160 hash function
*/
private byte[] RIPEMD160(byte[] tobeHashed){
RIPEMD160Digest digester = new RIPEMD160Digest();
byte[] retValue=new byte[digester.getDigestSize()];
digester.update(tobeHashed, 0, tobeHashed.length);
digester.doFinal(retValue, 0);
byte[] version = new byte[]{0x00};
return concateByteArray(version,retValue);
}
示例3: calculateBitcoinAddress
import org.bouncycastle.crypto.digests.RIPEMD160Digest; //导入方法依赖的package包/类
/**
* Calculates the bitcoinaddress for the given byte array containing the public key and returns
* it
* as a String.
*
* @param publicKey A byte array containing the public key to calulcate the address for
* @return The Bitcoin address as a Base58 encoded string
*/
public static String calculateBitcoinAddress(byte[] publicKey) {
RIPEMD160Digest ripemd160 = new RIPEMD160Digest();
MessageDigest sha256;
try {
sha256 = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
byte[] sha256Hash = sha256.digest(publicKey);
byte[] ripemdHash = new byte[ripemd160.getDigestSize() + 1];
ripemd160.update(sha256Hash, 0, sha256Hash.length);
ripemd160.doFinal(ripemdHash, 1);
// Set version byte
ripemdHash[0] = 0;
sha256Hash = sha256.digest(ripemdHash);
sha256Hash = sha256.digest(sha256Hash);
byte[] addressBytes = new byte[ripemdHash.length + 4];
System.arraycopy(ripemdHash, 0, addressBytes, 0, ripemdHash.length);
System.arraycopy(sha256Hash, 0, addressBytes, (ripemdHash.length), 4);
return Base58.encode(addressBytes);
}
示例4: getHashFromSignedTransaction
import org.bouncycastle.crypto.digests.RIPEMD160Digest; //导入方法依赖的package包/类
/**
* Get the hash of a signed transactoin
*
* @param signedTransaction the signed transaction as byte array
* @return the hash as String (Base58 encoded)
*/
public static String getHashFromSignedTransaction(byte[] signedTransaction) {
// TODO implemnt it correctly
RIPEMD160Digest ripemd160 = new RIPEMD160Digest();
MessageDigest sha256;
try {
sha256 = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
byte[] sha256Hash = sha256.digest(signedTransaction);
byte[] ripemdHash = new byte[ripemd160.getDigestSize() + 1];
ripemd160.update(sha256Hash, 0, sha256Hash.length);
ripemd160.doFinal(ripemdHash, 1);
// Set version byte
ripemdHash[0] = 0;
sha256Hash = sha256.digest(ripemdHash);
sha256Hash = sha256.digest(sha256Hash);
byte[] addressBytes = new byte[ripemdHash.length + 4];
System.arraycopy(ripemdHash, 0, addressBytes, 0, ripemdHash.length);
System.arraycopy(sha256Hash, 0, addressBytes, (ripemdHash.length), 4);
return Base58.encode(addressBytes);
}
示例5: createFromUserId
import org.bouncycastle.crypto.digests.RIPEMD160Digest; //导入方法依赖的package包/类
public static PgpUserIdNameHash createFromUserId(final String userId) {
assertNotNull(userId, "userId");
final RIPEMD160Digest digest = new RIPEMD160Digest();
byte[] userIdBytes = userId.getBytes(StandardCharsets.UTF_8); // TODO is this correct?! really UTF-8?! check with my own name! ;-)
digest.update(userIdBytes, 0, userIdBytes.length);
final byte[] out = new byte[digest.getDigestSize()];
digest.doFinal(out, 0);
return new PgpUserIdNameHash(out);
}
示例6: hash160
import org.bouncycastle.crypto.digests.RIPEMD160Digest; //导入方法依赖的package包/类
/**
* Calculate the RIPEMD160 hash of the input
*
* @param input The byte array to be hashed
* @return The hashed result
*/
public static byte[] hash160(byte[] input) {
byte[] out = new byte[20];
RIPEMD160Digest rDigest = new RIPEMD160Digest();
rDigest.update(input, 0, input.length);
rDigest.doFinal(out, 0);
return out;
}
示例7: sha256Hash160
import org.bouncycastle.crypto.digests.RIPEMD160Digest; //导入方法依赖的package包/类
/**
* Calculate RIPEMD160(SHA256(input)). This is used in Address calculations.
*
* @param input The byte array to be hashed
* @return The hashed result
*/
public static byte[] sha256Hash160(byte[] input) {
byte[] out = new byte[20];
synchronized(digest) {
digest.reset();
byte[] sha256 = digest.digest(input);
RIPEMD160Digest rDigest = new RIPEMD160Digest();
rDigest.update(sha256, 0, sha256.length);
rDigest.doFinal(out, 0);
}
return out;
}
示例8: getAddress
import org.bouncycastle.crypto.digests.RIPEMD160Digest; //导入方法依赖的package包/类
public StellarAddress getAddress(){
// Hashing of the publicKey is performed with a single SHA256 instead of
// the typical Stellar HalfSHA512
SHA256Digest sha256Digest = new SHA256Digest();
sha256Digest.update(payloadBytes, 0, payloadBytes.length);
byte[] sha256PubKeyBytes = new byte[32];
sha256Digest.doFinal(sha256PubKeyBytes, 0);
RIPEMD160Digest digest = new RIPEMD160Digest();
digest.update(sha256PubKeyBytes, 0, sha256PubKeyBytes.length);
byte[] accountIdBytes = new byte[20];
digest.doFinal(accountIdBytes, 0);
return new StellarAddress(accountIdBytes);
}
示例9: getPublicAddress
import org.bouncycastle.crypto.digests.RIPEMD160Digest; //导入方法依赖的package包/类
/**
* Convert a key into its corresponding public address.
*
* @param key Key to convert
* @param isPrivateKey Is this private or public
* @return Public bitcoin address.
*/
public static String getPublicAddress(String key, boolean isPrivateKey) {
try {
byte[] publicKeyBytes;
if (isPrivateKey) {
publicKeyBytes = getPublicKeyBytes(key);
} else {
publicKeyBytes = ByteUtilities.toByteArray(key);
}
MessageDigest md = MessageDigest.getInstance(SHA256);
md.reset();
md.update(publicKeyBytes);
byte[] publicShaKeyBytes = md.digest();
RIPEMD160Digest ripemd = new RIPEMD160Digest();
byte[] publicRipemdKeyBytes = new byte[20];
ripemd.update(publicShaKeyBytes, 0, publicShaKeyBytes.length);
ripemd.doFinal(publicRipemdKeyBytes, 0);
// Add network bytes
String networkBytes =
BitcoinResource.getResource().getBitcoindRpc().getblockchaininfo().getChain()
== BlockChainName.main ? NetworkBytes.P2PKH.toString() :
NetworkBytes.P2PKH_TEST.toString();
byte[] networkPublicKeyBytes = ByteUtilities.toByteArray(networkBytes);
byte[] networkPublicKeyBytes2 =
new byte[networkPublicKeyBytes.length + publicRipemdKeyBytes.length];
System.arraycopy(networkPublicKeyBytes, 0, networkPublicKeyBytes2, 0,
networkPublicKeyBytes.length);
System
.arraycopy(publicRipemdKeyBytes, 0, networkPublicKeyBytes2, networkPublicKeyBytes.length,
publicRipemdKeyBytes.length);
networkPublicKeyBytes = new byte[networkPublicKeyBytes2.length];
System.arraycopy(networkPublicKeyBytes2, 0, networkPublicKeyBytes, 0,
networkPublicKeyBytes2.length);
md = MessageDigest.getInstance(SHA256);
md.reset();
md.update(networkPublicKeyBytes);
byte[] publicKeyChecksum = Arrays.copyOfRange(md.digest(md.digest()), 0, 4);
byte[] decodedPublicKey = new byte[networkPublicKeyBytes.length + publicKeyChecksum.length];
System.arraycopy(networkPublicKeyBytes, 0, decodedPublicKey, 0, networkPublicKeyBytes.length);
System.arraycopy(publicKeyChecksum, 0, decodedPublicKey, networkPublicKeyBytes.length,
publicKeyChecksum.length);
return Base58.encode(decodedPublicKey);
} catch (Exception e) {
LOGGER.error("Unable to get network information when creating address", e);
return null;
}
}