当前位置: 首页>>代码示例>>Java>>正文


Java SHA3Digest.update方法代码示例

本文整理汇总了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;
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:12,代码来源:EncryptionUtil.java

示例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()]);
}
 
开发者ID:Braveno,项目名称:cosigner,代码行数:30,代码来源:ServerKey.java

示例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;
}
 
开发者ID:blmalone,项目名称:Blockchain-Academic-Verification-Service,代码行数:14,代码来源:HashingUtils.java

示例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;
}
 
开发者ID:Braveno,项目名称:cosigner,代码行数:47,代码来源:ClusterInfo.java


注:本文中的org.bouncycastle.crypto.digests.SHA3Digest.update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。