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

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

Best Java code snippets using io.yggdrash.common.crypto.HashUtil.sha3 (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

/**
 * 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

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

public byte[] getHash() {
  ByteArrayOutputStream bao = new ByteArrayOutputStream();
  try {
    bao.write(this.header.toBinary());
    bao.write(this.signature);
  } catch (IOException e) {
    log.warn("getHash() ioException");
    throw new NotValidateException();
  }
  return HashUtil.sha3(bao.toByteArray());
}
origin: yggdrash/yggdrash

private String approveKey(String sender, String spender) {
  byte[] approveKeyByteArray = ByteUtil.merge(sender.getBytes(), spender.getBytes());
  byte[] approveKey = HashUtil.sha3(approveKeyByteArray);
  return Hex.toHexString(approveKey);
}
origin: yggdrash/yggdrash

/**
 * Verify the signature with plain data.
 *
 * @param data      plain data for signed
 * @param signature signature
 * @return verification result
 */
public boolean verify(byte[] data, byte[] signature) {
  ECKey.ECDSASignature sig = new ECKey.ECDSASignature(signature);
  return key.verify(HashUtil.sha3(data), sig);
}
origin: yggdrash/yggdrash

/**
 * Sign the plain data.
 *
 * @param data plain data
 * @return signature as byte[65]
 */
public byte[] sign(byte[] data) {
  return key.sign(HashUtil.sha3(data)).toBinary();
}
origin: yggdrash/yggdrash

public static byte[] calculatePubKey(byte[] data, byte[] signature, boolean hashed) {
  ECKey.ECDSASignature ecdsaSignature = new ECKey.ECDSASignature(signature);
  byte[] hashedData = hashed ? data : HashUtil.sha3(data);
  ECKey ecKeyPub;
  try {
    ecKeyPub = ECKey.signatureToKey(hashedData, ecdsaSignature);
  } catch (SignatureException e) {
    logger.debug("Invalid signature" + e.getMessage());
    return null;
  }
  return ecKeyPub.getPubKey();
}
origin: yggdrash/yggdrash

@Test
public void test1() {
  byte[] result = sha3("horse".getBytes());
  assertEquals("c87f65ff3f271bf5dc8643484f66b200109caffe4bf98c4cb393dc35740b28c0",
      Hex.toHexString(result));
  result = sha3("cow".getBytes());
  assertEquals("c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4",
      Hex.toHexString(result));
}
origin: yggdrash/yggdrash

@Test
public void testVerifySignature1() {
  ECKey key = ECKey.fromPublicOnly(pubKey);
  BigInteger r = new BigInteger("95350169487015575001444507567851457309689354890536757640816472151471942911739");
  BigInteger s = new BigInteger("53263359985948886716508128220321578640585687230908938312863706887350789467339");
  ECDSASignature sig = ECDSASignature.fromComponents(r.toByteArray(), s.toByteArray(), (byte) 28);
  assertTrue(key.verify(HashUtil.sha3(exampleMessage.getBytes()), sig));
}
origin: yggdrash/yggdrash

@Test /* real block hash calc */
public void test8() {
  String blockRaw = "F885F8818080A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347940000000000000000000000000000000000000000A0BCDDD284BF396739C224DBA0411566C891C32115FEB998A3E2B4E61F3F35582AA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D4934783800000808080C0C0";
  byte[] blockHashB = sha3(Hex.decode(blockRaw));
  String blockHash = Hex.toHexString(blockHashB);
  log.debug(blockHash);
}
origin: yggdrash/yggdrash

/**
 * Verified via https://etherchain.org/verify/signature
 */
@Test
public void testEthereumSignToHex() {
  ECKey key = ECKey.fromPrivate(privateKey);
  byte[] messageHash = HashUtil.sha3(exampleMessage.getBytes());
  ECDSASignature signature = key.sign(messageHash);
  String output = signature.toHex();
  log.debug("Signature\t: " + output + " (Hex, length: " + output.length() + ")");
  assertEquals(signatureHex, output);
}
origin: yggdrash/yggdrash

@Test
public void testEthereumSign() {
  ECKey key = ECKey.fromPrivate(privateKey);
  log.debug("Secret\t: " + Hex.toHexString(key.getPrivKeyBytes()));
  log.debug("Pubkey\t: " + Hex.toHexString(key.getPubKey()));
  log.debug("Data\t: " + exampleMessage);
  byte[] messageHash = HashUtil.sha3(exampleMessage.getBytes());
  ECDSASignature signature = key.sign(messageHash);
  String output = signature.toBase64();
  log.debug("Sign\t: " + output + " (Base64, length: " + output.length() + ")");
  assertEquals(sigBase64, output);
}
origin: yggdrash/yggdrash

@Test
public void test4() {
  byte[] cowBytes = sha3("cow".getBytes());
  byte[] addr = ECKey.fromPrivate(cowBytes).getAddress();
  assertEquals("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826", Hex.toHexString(addr).toUpperCase());
}
origin: yggdrash/yggdrash

@Test
public void test5() {
  byte[] horseBytes = sha3("horse".getBytes());
  byte[] addr = ECKey.fromPrivate(horseBytes).getAddress();
  assertEquals("13978AEE95F38490E9769C39B2773ED763D9CD5F", Hex.toHexString(addr).toUpperCase());
}
origin: yggdrash/yggdrash

@Test
public void testVerifySignature5() {
  ECKey key = ECKey.fromPrivate(privateKey);
  byte[] messageHash = HashUtil.sha3(exampleMessage.getBytes());
  ECDSASignature signature = key.sign(messageHash);
  assertTrue(key.verify(messageHash, signature));
}
origin: yggdrash/yggdrash

@Test
public void testSignedMessageToKey() throws SignatureException {
  byte[] messageHash = HashUtil.sha3(exampleMessage.getBytes());
  ECKey key = ECKey.signatureToKey(messageHash, sigBase64);
  assertNotNull(key);
  assertArrayEquals(pubKey, key.getPubKey());
}
origin: yggdrash/yggdrash

@Test /* real tx hash calc */
public void test7() {
  String txRaw = "F89D80809400000000000000000000000000000000000000008609184E72A000822710B3606956330C0D630000003359366000530A0D630000003359602060005301356000533557604060005301600054630000000C5884336069571CA07F6EB94576346488C6253197BDE6A7E59DDC36F2773672C849402AA9C402C3C4A06D254E662BF7450DD8D835160CBB053463FED0B53F2CDD7F3EA8731919C8E8CC";
  byte[] txHashB = sha3(Hex.decode(txRaw));
  String txHash = Hex.toHexString(txHashB);
  assertEquals("4b7d9670a92bf120d5b43400543b69304a14d767cf836a7f6abff4edde092895", txHash);
}
origin: yggdrash/yggdrash

private void testProviderRoundTrip(Provider provider) {
  ECKey key = new ECKey(provider, secureRandom);
  String message = "The quick brown fox jumps over the lazy dog.";
  byte[] input = HashUtil.sha3(message.getBytes());
  ECDSASignature sig = key.sign(input);
  assertTrue(sig.validateComponents());
  assertTrue(key.verify(input, sig));
}
origin: yggdrash/yggdrash

@Test
public void testSignVerify() {
  ECKey key = ECKey.fromPrivate(privateKey);
  String message = "This is an example of a signed message.";
  byte[] input = HashUtil.sha3(message.getBytes());
  ECDSASignature sig = key.sign(input);
  assertTrue(sig.validateComponents());
  assertTrue(key.verify(input, sig));
}
io.yggdrash.common.cryptoHashUtilsha3

Javadoc

SHA3(Keccak256) Hash Method.

Popular methods of HashUtil

  • 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 post requests using okhttp
  • onRequestPermissionsResult (Fragment)
  • getApplicationContext (Context)
  • setRequestProperty (URLConnection)
  • BufferedWriter (java.io)
    Wraps an existing Writer and buffers the output. Expensive interaction with the underlying reader is
  • ResultSet (java.sql)
    An interface for an object which represents a database table entry, returned as the result of the qu
  • LinkedHashMap (java.util)
    LinkedHashMap is an implementation of Map that guarantees iteration order. All optional operations a
  • Random (java.util)
    This class provides methods that return pseudo-random values.It is dangerous to seed Random with the
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • Table (org.hibernate.mapping)
    A relational table
  • 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