本文整理汇总了Java中org.bouncycastle.crypto.digests.SHA3Digest.update方法的典型用法代码示例。如果您正苦于以下问题:Java SHA3Digest.update方法的具体用法?Java SHA3Digest.update怎么用?Java SHA3Digest.update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.crypto.digests.SHA3Digest
的用法示例。
在下文中一共展示了SHA3Digest.update方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSha3Hash
import org.bouncycastle.crypto.digests.SHA3Digest; //导入方法依赖的package包/类
public static String getSha3Hash(String data) {
String trimmedData = trimNewLines(data);
byte[] dataBytes = trimmedData.getBytes();
SHA3Digest md = new SHA3Digest(256);
md.reset();
md.update(dataBytes, 0, dataBytes.length);
byte[] hashedBytes = new byte[256 / 8];
md.doFinal(hashedBytes, 0);
String sha3Hash = ByteUtils.toHexString(hashedBytes);
return sha3Hash;
}
示例2: getClusterSignature
import org.bouncycastle.crypto.digests.SHA3Digest; //导入方法依赖的package包/类
/**
* Signs the server's public ID with the cluster key.
*/
public static String[] getClusterSignature(String clusterKey) {
LinkedList<String> rsvValues = new LinkedList<>();
while (rsvValues.isEmpty()) {
// Hash the public key
SHA3Digest sha3 = new SHA3Digest(256);
sha3.reset();
sha3.update(Secp256k1.getPublicKey(myKey), 0, Secp256k1.getPublicKey(myKey).length);
byte[] hashedBytes = new byte[256 / 8];
sha3.doFinal(hashedBytes, 0);
// Sign it.
byte[][] signature =
Secp256k1.signTransaction(hashedBytes, ByteUtilities.toByteArray(clusterKey));
Arrays.asList(signature)
.forEach(sigValue -> rsvValues.add(ByteUtilities.toHexString(sigValue)));
// Recovery ID is bad, try again.
if (rsvValues.get(2).equalsIgnoreCase("ff")) {
LOGGER.debug("Problem getting signature, V is invalid.");
LOGGER.debug(rsvValues.toString());
rsvValues.clear();
}
}
return rsvValues.toArray(new String[rsvValues.size()]);
}
示例3: hashToBytes
import org.bouncycastle.crypto.digests.SHA3Digest; //导入方法依赖的package包/类
/**
* Hashes a string using SHA3 to a specified strength.
* @param input the string to hash
* @return The hashed string as a byte array
* @throws UnsupportedEncodingException
*/
public static byte[] hashToBytes(final String input) throws UnsupportedEncodingException {
SHA3Digest sha3Digest = new SHA3Digest(HASH_STRENGTH);
sha3Digest.update(input.getBytes(UTF_8), 0, input.length());
byte[] result = new byte[sha3Digest.getDigestSize()];
sha3Digest.doFinal(result, 0);
return result;
}
示例4: addServer
import org.bouncycastle.crypto.digests.SHA3Digest; //导入方法依赖的package包/类
/**
* Add a server to our known hosts.
*
* <p>Returns true or false depending on whether the server's signature is acceptable or not.
*/
public boolean addServer(Server server, boolean wasHeartbeat) {
LOGGER.debug("Attempting to add a server: " + server);
LOGGER.debug("Is a heartbeat: " + wasHeartbeat);
if (!getThisServer().equals(server)) {
server.setOriginator(false);
}
byte[] data = ByteUtilities.toByteArray(server.getServerId());
// Hash the public key
SHA3Digest sha3 = new SHA3Digest(256);
sha3.reset();
sha3.update(data, 0, data.length);
byte[] hashedBytes = new byte[256 / 8];
sha3.doFinal(hashedBytes, 0);
String recoveredPublicKey = ByteUtilities.toHexString(Secp256k1
.recoverPublicKey(ByteUtilities.toByteArray(server.getSigR()),
ByteUtilities.toByteArray(server.getSigS()),
ByteUtilities.toByteArray(server.getSigV()), hashedBytes));
String publicKey =
ByteUtilities.toHexString(Secp256k1.getPublicKey(ByteUtilities.toByteArray(clusterKey)));
if (!publicKey.equalsIgnoreCase(recoveredPublicKey)) {
LOGGER.debug("Server doesn't belong to this cluster.");
return false;
}
if (wasHeartbeat) {
// If it was a hearbeat then remove the old one so that we replace it, and update the time.
if (this.getServers().contains(server)) {
this.getServers().remove(server);
}
server.setLastCommunication(System.currentTimeMillis());
} else {
// Otherwise, write in an unknown time if we don't already have an entry for it.
server.setLastCommunication(0L);
}
this.getServers().add(server);
return true;
}