Tabnine Logo
HashUtil
Code IndexAdd Tabnine to your IDE (free)

How to use
HashUtil
in
io.yggdrash.common.crypto

Best Java code snippets using io.yggdrash.common.crypto.HashUtil (Showing top 20 results out of 315)

origin: yggdrash/yggdrash

private Sha3Hash(byte[] data, boolean hashed) {
  if (hashed) {
    this.data = data;
  } else {
    this.data = HashUtil.sha3(data);
  }
}
origin: yggdrash/yggdrash

/**
 * SHA1 Hash Method.
 *
 * @param input data
 * @return hashed data
 */
public static byte[] sha1(byte[] input) {
  return hash(input, HASH_SHA_1_ALGORITHM_NAME);
}
origin: yggdrash/yggdrash

/**
 * Compute an address from an encoded public key.
 *
 * @param pubBytes an encoded (uncompressed) public key
 * @return 20-byte address
 */
public static byte[] computeAddress(byte[] pubBytes) {
  return HashUtil.sha3omit12(
      Arrays.copyOfRange(pubBytes, 1, pubBytes.length));
}
origin: yggdrash/yggdrash

@Test
public void PBKDF2_SHA256_Random_Test() {
  String password = "testpassword";
  int iterations = 262144;
  int len = 32;
  byte[] salt = new byte[32];
  SecureRandom prng = new SecureRandom();
  prng.nextBytes(salt);
  log.info("salt= {}", Hex.toHexString(salt));
  byte[] pbkdf2Password = HashUtil.pbkdf2(password.getBytes(), salt, iterations, len, "SHA-256");
  log.info(Hex.toHexString(pbkdf2Password));
  assertNotNull(pbkdf2Password);
}
origin: yggdrash/yggdrash

prng.nextBytes(salt);
byte[] kdfPass = HashUtil.pbkdf2(
    password.getBytes(),
    salt,
    ByteUtil.parseBytes(kdfPass, 0, 16),
    iv);
byte[] mac = HashUtil.hash(
    ByteUtil.merge(ByteUtil.parseBytes(kdfPass, 16, 16), encData),
    WALLET_PBKDF2_HMAC_HASH);
origin: yggdrash/yggdrash

static ContractId of(byte[] contractBytes) {
  return new ContractId(HashUtil.sha1(contractBytes));
}
origin: yggdrash/yggdrash

@Test
public void keyRecovery() {
  ECKey key = new ECKey();
  String message = "Hello World!";
  byte[] hash = HashUtil.sha256(message.getBytes());
  ECKey.ECDSASignature sig = key.doSign(hash);
  key = ECKey.fromPublicOnly(key.getPubKeyPoint());
  boolean found = false;
  for (int i = 0; i < 4; i++) {
    ECKey key2 = ECKey.recoverFromSignature(i, sig, hash);
    checkNotNull(key2);
    if (key.equals(key2)) {
      found = true;
      break;
    }
  }
  assertTrue(found);
}
origin: yggdrash/yggdrash

@Test
public void PBKDF2_SHA3512_Test() {
  String password = "testpassword";
  byte[] salt = Hex.decode("ae3cd4e7013836a3df6bd7241b12db061dbe2c6785853cce422d148a624ce0bd");
  int iterations = 262144;
  int len = 32;
  byte[] pbkdf2Password = HashUtil.pbkdf2(password.getBytes(), salt, iterations, len, "SHA3-512");
  log.info(Hex.toHexString(pbkdf2Password));
  assertArrayEquals(Hex.decode("2cf80c8e19136485eb79eba7349c8f334582f3b7f22e48e07124c4b5a85631c7"), pbkdf2Password);
}
origin: yggdrash/yggdrash

    .get("salt")
    .getAsString());
byte[] kdfPass = HashUtil.pbkdf2(
    password.getBytes(),
    salt,
    .getAsString());
byte[] newMac = HashUtil.hash(
    ByteUtil.merge(ByteUtil.parseBytes(kdfPass, 16, 16), encData),
    WALLET_PBKDF2_HMAC_HASH);
origin: yggdrash/yggdrash

/**
 * Calculates RIGTMOST160(SHA3(input)). This is used in address
 * calculations. *
 *
 * @param input - data
 * @return - 20 right bytes of the hash keccak of the data
 */
public static byte[] sha3omit12(byte[] input) {
  byte[] hash = sha3(input);
  return copyOfRange(hash, 12, hash.length);
}
origin: yggdrash/yggdrash

/**
 * SHA256 Hash Method.
 *
 * @param input - data for hashing
 * @return - sha256 hash of the data
 */
static byte[] sha256(byte[] input) {
  return hash(input, HASH_SHA_256_ALGORITHM_NAME);
}
origin: yggdrash/yggdrash

@Test
public void PBKDF2_SHA512_Test() {
  String password = "testpassword";
  byte[] salt = Hex.decode("ae3cd4e7013836a3df6bd7241b12db061dbe2c6785853cce422d148a624ce0bd");
  int iterations = 262144;
  int len = 32;
  byte[] pbkdf2Password = HashUtil.pbkdf2(password.getBytes(), salt, iterations, len, "SHA-512");
  log.info(Hex.toHexString(pbkdf2Password));
  assertArrayEquals(Hex.decode("5e005b008b20c7ab157725ed2f72faa4357a51eddac85837ca7d925e8daa0d41"), pbkdf2Password);
}
origin: yggdrash/yggdrash

public static byte[] calculateAddress(byte[] publicKey) {
  return HashUtil.sha3omit12(
      Arrays.copyOfRange(publicKey, 1, publicKey.length));
}
origin: yggdrash/yggdrash

private byte[] blockIndexKey(long index) {
  String blockIndexKey = "BLOCK_INDEX_" + Long.toString(index);
  return HashUtil.sha3(blockIndexKey.getBytes());
}
origin: yggdrash/yggdrash

/**
 * The hash method for supporting many algorithms.
 *
 * @param input     data for hashing.
 * @param algorithm algorithm for hashing. ex) "KECCAK-256", "SHA-256", "SHA3-256", "SHA-1"
 * @return hashed data.
 */
public static byte[] hash(byte[] input, String algorithm) {
  return hash(input, algorithm, false);
}
origin: yggdrash/yggdrash

@Test
public void PBKDF2_SHA1_Test() {
  String password = "testpassword";
  byte[] salt = Hex.decode("ae3cd4e7013836a3df6bd7241b12db061dbe2c6785853cce422d148a624ce0bd");
  int iterations = 262144;
  int len = 32;
  byte[] pbkdf2Password = HashUtil.pbkdf2(password.getBytes(), salt, iterations, len, "SHA-1");
  log.info(Hex.toHexString(pbkdf2Password));
  assertArrayEquals(Hex.decode("279af536192ea4f5dac04f96471d94ea174c38d4b9a9a908f03217a215fc01f8"), pbkdf2Password);
}
origin: yggdrash/yggdrash

/**
 * Get the address as binary.
 *
 * @return address
 */
public byte[] getAddress() throws SignatureException {
  byte[] pubKey = this.getPubKey();
  return HashUtil.sha3omit12(
      Arrays.copyOfRange(pubKey, 1, pubKey.length));
}
origin: yggdrash/yggdrash

/**
 * Get the headerHash for signing.
 *
 * @return hash of header
 */
public byte[] getHashForSigning() {
  return HashUtil.sha3(this.toBinary());
}
origin: yggdrash/yggdrash

/**
 * SHA3(Keccak256) Hash Method.
 *
 * @param input data
 * @return hashed data
 */
public static byte[] sha3(byte[] input) {
  return hash(input, HASH_256_ALGORITHM_NAME);
}
origin: yggdrash/yggdrash

@Test
public void PBKDF2_SHA3256_Test() {
  String password = "testpassword";
  byte[] salt = Hex.decode("ae3cd4e7013836a3df6bd7241b12db061dbe2c6785853cce422d148a624ce0bd");
  int iterations = 262144;
  int len = 32;
  byte[] pbkdf2Password = HashUtil.pbkdf2(password.getBytes(), salt, iterations, len, "SHA3-256");
  log.info(Hex.toHexString(pbkdf2Password));
  assertArrayEquals(Hex.decode("2761ad467ba3d88c8c331e93829ec5ce912048037c50c8d5faeb4af87bbeb102"), pbkdf2Password);
}
io.yggdrash.common.cryptoHashUtil

Most used methods

  • sha3
    SHA3(Keccak256) Hash Method.
  • hash
    The hash method for supporting many algorithms.
  • pbkdf2
    Get pbkdf2's hash encrypted output(key).
  • sha3omit12
    Calculates RIGTMOST160(SHA3(input)). This is used in address calculations.
  • sha1
    SHA1 Hash Method.
  • sha256
    SHA256 Hash Method.

Popular in Java

  • Making http requests using okhttp
  • getExternalFilesDir (Context)
  • getApplicationContext (Context)
  • runOnUiThread (Activity)
  • Pointer (com.sun.jna)
    An abstraction for a native pointer data type. A Pointer instance represents, on the Java side, a na
  • Window (java.awt)
    A Window object is a top-level window with no borders and no menubar. The default layout for a windo
  • SocketException (java.net)
    This SocketException may be thrown during socket creation or setting options, and is the superclass
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • MessageFormat (java.text)
    Produces concatenated messages in language-neutral way. New code should probably use java.util.Forma
  • Arrays (java.util)
    This class contains various methods for manipulating arrays (such as sorting and searching). This cl
  • Github Copilot alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now