/** * Calculates the SHA-256 hash of the given bytes. * * @param input the bytes to hash * @return the hash (in big-endian order) */ public static byte[] hash(byte[] input) { return hash(input, 0, input.length); }
/** * Calculates the SHA-256 hash of the given bytes. * * @param input the bytes to hash * @return the hash (in big-endian order) */ public static byte[] hash(byte[] input) { return hash(input, 0, input.length); }
/** * Calculates the SHA-256 hash of the given bytes. * * @param input the bytes to hash * @return the hash (in big-endian order) */ public static byte[] hash(byte[] input) { return hash(input, 0, input.length); }
/** * Calculates the SHA-256 hash of the given bytes. * * @param input the bytes to hash * @return the hash (in big-endian order) */ public static byte[] hash(byte[] input) { return hash(input, 0, input.length); }
public static byte[] message(byte[] payload, byte[] prevMagicHash) throws IOException { if (prevMagicHash == null) return payload; else { final byte[] payloadHash = Sha256Hash.hash(payload); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); outputStream.write(prevMagicHash); outputStream.write(payloadHash); return outputStream.toByteArray(); } }
/** * Creates a new instance containing the calculated (one-time) hash of the given bytes. * * @param contents the bytes on which the hash value is calculated * @return a new instance containing the calculated (one-time) hash */ public static Sha256Hash of(byte[] contents) { return wrap(hash(contents)); }
/** * Creates a new instance containing the calculated (one-time) hash of the given bytes. * * @param contents the bytes on which the hash value is calculated * @return a new instance containing the calculated (one-time) hash */ public static Sha256Hash of(byte[] contents) { return wrap(hash(contents)); }
/** * Creates a new instance containing the calculated (one-time) hash of the given bytes. * * @param contents the bytes on which the hash value is calculated * @return a new instance containing the calculated (one-time) hash */ public static Sha256Hash of(byte[] contents) { return wrap(hash(contents)); }
/** * Creates a new instance containing the calculated (one-time) hash of the given bytes. * * @param contents the bytes on which the hash value is calculated * @return a new instance containing the calculated (one-time) hash */ public static Sha256Hash of(byte[] contents) { return wrap(hash(contents)); }
/** * Creates a segwit P2WSH pubKeyScript for provided script. */ public static Script createP2WSHOutputScript(Script segwitScript) { byte[] hash = Sha256Hash.hash(segwitScript.getProgram()); return ScriptBuilder.createP2WSHOutputScript(hash); }
/** * Creates a segwit P2WSH pubKeyScript for provided script. */ public static Script createP2WSHOutputScript(Script segwitScript) { byte[] hash = Sha256Hash.hash(segwitScript.getProgram()); return ScriptBuilder.createP2WSHOutputScript(hash); }
/** * Calculates RIPEMD160(SHA256(input)). This is used in Address calculations. */ public static byte[] sha256hash160(byte[] input) { byte[] sha256 = Sha256Hash.hash(input); RIPEMD160Digest digest = new RIPEMD160Digest(); digest.update(sha256, 0, sha256.length); byte[] out = new byte[20]; digest.doFinal(out, 0); return out; }
/** * Calculates RIPEMD160(SHA256(input)). This is used in Address calculations. */ public static byte[] sha256hash160(byte[] input) { byte[] sha256 = Sha256Hash.hash(input); RIPEMD160Digest digest = new RIPEMD160Digest(); digest.update(sha256, 0, sha256.length); byte[] out = new byte[20]; digest.doFinal(out, 0); return out; }
/** * Calculates RIPEMD160(SHA256(input)). This is used in Address calculations. */ public static byte[] sha256hash160(byte[] input) { byte[] sha256 = Sha256Hash.hash(input); RIPEMD160Digest digest = new RIPEMD160Digest(); digest.update(sha256, 0, sha256.length); byte[] out = new byte[20]; digest.doFinal(out, 0); return out; }
/** * Calculates RIPEMD160(SHA256(input)). This is used in Address calculations. */ public static byte[] sha256hash160(byte[] input) { byte[] sha256 = Sha256Hash.hash(input); RIPEMD160Digest digest = new RIPEMD160Digest(); digest.update(sha256, 0, sha256.length); byte[] out = new byte[20]; digest.doFinal(out, 0); return out; }
@Test public void decrypt_withKey() throws Exception { String key = "80a150a8aae2c159cdad74fd675f03238fe5b8c884b976f8abfe56e621fd7ee1";//"Dylan Thomas"; String data = "Do not go gentle into that good night."; byte[] keyBytes = Sha256Hash.hash(key.getBytes()); byte[] encrypted = AESUtil.encryptWithKey(keyBytes, data); String decrypted = AESUtil.decryptWithKey(keyBytes, new String(encrypted)); Assert.assertTrue("Decryption", decrypted.equals(data)); } }
@VisibleForTesting public InetSocketAddress[] protoToAddrs(PeerSeedProtos.SignedPeerSeeds proto) throws PeerDiscoveryException, InvalidProtocolBufferException, SignatureException { if (details.pubkey != null) { if (!Arrays.equals(proto.getPubkey().toByteArray(), details.pubkey.getPubKey())) throw new PeerDiscoveryException("Public key mismatch"); byte[] hash = Sha256Hash.hash(proto.getPeerSeeds().toByteArray()); details.pubkey.verifyOrThrow(hash, proto.getSignature().toByteArray()); } PeerSeedProtos.PeerSeeds seeds = PeerSeedProtos.PeerSeeds.parseFrom(proto.getPeerSeeds()); if (seeds.getTimestamp() < Utils.currentTimeSeconds() - (60 * 60 * 24)) throw new PeerDiscoveryException("Seed data is more than one day old: replay attack?"); if (!seeds.getNet().equals(params.getPaymentProtocolId())) throw new PeerDiscoveryException("Network mismatch"); InetSocketAddress[] results = new InetSocketAddress[seeds.getSeedCount()]; int i = 0; for (PeerSeedProtos.PeerSeedData data : seeds.getSeedList()) results[i++] = new InetSocketAddress(data.getIpAddress(), data.getPort()); return results; }
public String encryptFor(String xpub, String payload) throws UnsupportedEncodingException, InvalidCipherTextException { ECKey myKey = getNode(); DeterministicKey otherKey = DeterministicKey.deserializeB58(null, xpub, PersistentUrls.getInstance().getCurrentNetworkParams()); byte[] sharedSecret = otherKey.getPubKeyPoint().multiply(myKey.getPrivKey()).getEncoded(); byte[] sharedKey = Sha256Hash.hash(sharedSecret); return new String(AESUtil.encryptWithKey(sharedKey, payload)); }
public String decryptFrom(String xpub, String payload) throws UnsupportedEncodingException, InvalidCipherTextException { ECKey myKey = getNode(); DeterministicKey otherKey = DeterministicKey.deserializeB58(null, xpub, PersistentUrls.getInstance().getCurrentNetworkParams()); byte[] sharedSecret = otherKey.getPubKeyPoint().multiply(myKey.getPrivKey()).getEncoded(); byte[] sharedKey = Sha256Hash.hash(sharedSecret); return AESUtil.decryptWithKey(sharedKey, payload); }
private MarriedKeyChain createMarriedKeyChain() { byte[] entropy = Sha256Hash.hash("don't use a seed like this in real life".getBytes()); DeterministicSeed seed = new DeterministicSeed(entropy, "", MnemonicCode.BIP39_STANDARDISATION_TIME_SECS); MarriedKeyChain chain = MarriedKeyChain.builder() .seed(seed) .followingKeys(watchingAccountKey) .threshold(2).build(); return chain; }