public static BloomKFilterHolder fromBloomKFilter(BloomKFilter filter) throws IOException { byte[] bytes = BloomFilterSerializersModule.bloomKFilterToBytes(filter); return new BloomKFilterHolder(filter, Hashing.sha512().hashBytes(bytes)); }
public static BloomKFilterHolder fromBytes(byte[] bytes) throws IOException { return new BloomKFilterHolder( BloomFilterSerializersModule.bloomKFilterFromBytes(bytes), Hashing.sha512().hashBytes(bytes) ); }
public void testSha512() { HashTestUtils.checkAvalanche(Hashing.sha512(), 100, 0.4); HashTestUtils.checkNo2BitCharacteristics(Hashing.sha512()); HashTestUtils.checkNoFunnels(Hashing.sha512()); HashTestUtils.assertInvariants(Hashing.sha512()); assertEquals("Hashing.sha512()", Hashing.sha512().toString()); }
@Description("compute sha512 hash") @ScalarFunction @SqlType(StandardTypes.VARBINARY) public static Slice sha512(@SqlType(StandardTypes.VARBINARY) Slice slice) { return Slices.wrappedBuffer(Hashing.sha512().hashBytes(slice.getBytes()).asBytes()); }
public void testToString() { assertEquals("Hashing.md5()", Hashing.md5().toString()); assertEquals("Hashing.sha1()", Hashing.sha1().toString()); assertEquals("Hashing.sha256()", Hashing.sha256().toString()); assertEquals("Hashing.sha512()", Hashing.sha512().toString()); }
if (bytes != null) ourHash = Hashing.sha512().hashBytes(bytes).toString();
static String hash(String apiKey) { if (!apiKey.startsWith(HASH_PREFIX)) { return HASH_PREFIX + Hashing.sha512().hashString(apiKey, StandardCharsets.UTF_8).toString(); } return apiKey; }
static String hash(String password) { if (!password.startsWith(HASH_PREFIX)) { return HASH_PREFIX + Hashing.sha512().hashString(password, StandardCharsets.UTF_8).toString(); } return password; }
@Override public String encrypt(String password) { requireNonNull(password, "Required non-null password"); // generate salt final byte[] salt = new byte[SALT_BYTES_LENGTH]; SECURE_RANDOM.nextBytes(salt); // sha512(password + salt) final HashCode hash = Hashing.sha512().hashBytes(Bytes.concat(password.getBytes(PWD_CHARSET), salt)); final HashCode saltHash = HashCode.fromBytes(salt); // add salt to the hash, result length (512 / 8) * 2 + (64 / 8) * 2 = 144 return hash.toString() + saltHash.toString(); }
@Override public boolean test(String password, String passwordHash) { requireNonNull(password, "Required non-null password"); requireNonNull(passwordHash, "Required non-null password's hash"); // retrieve salt from the hash final int passwordHashLength = ENCRYPTED_PASSWORD_BYTES_LENGTH * 2; if (passwordHash.length() < passwordHashLength + SALT_BYTES_LENGTH * 2) { return false; } final HashCode saltHash = HashCode.fromString(passwordHash.substring(passwordHashLength)); // sha1(password + salt) final HashCode hash = Hashing.sha512() .hashBytes(Bytes.concat(password.getBytes(PWD_CHARSET), saltHash.asBytes())); // test sha1(password + salt) + salt == passwordHash return (hash.toString() + saltHash.toString()).equals(passwordHash); } }
@SuppressWarnings("deprecation") private static HashFunction chooseHashing(String algorithm) { switch (algorithm) { case "MD5": return Hashing.md5(); case "SHA-256": return Hashing.sha256(); case "SHA-512": return Hashing.sha512(); default: return Hashing.sha1(); } }
@Override protected void processPacketPayload(Packet packet, byte[] payload) { if (payload.length > 0) { packet.put(HashPayloadPacket.PAYLOAD_SHA1_HASH, Hashing.sha1().hashBytes(payload).toString()); packet.put(HashPayloadPacket.PAYLOAD_SHA256_HASH, Hashing.sha256().hashBytes(payload).toString()); packet.put(HashPayloadPacket.PAYLOAD_SHA512_HASH, Hashing.sha512().hashBytes(payload).toString()); packet.put(HashPayloadPacket.PAYLOAD_MD5_HASH, Hashing.md5().hashBytes(payload).toString()); } } }
public FileSystemPointer(File target) { try { this.target = target; this.tag = Files.hash(target, Hashing.sha512()); final String contentType = java.nio.file.Files.probeContentType(target.toPath()); this.mediaTypeOrNull = contentType != null ? MediaType.parse(contentType) : null; } catch (IOException e) { throw new IllegalArgumentException(e); } }
public static HashCode getFileHash(File file) throws IOException { return Files.asByteSource(file).hash(Hashing.sha512()); }
private String generateConfirmationLink() { final String confirmationCode = Hashing.sha512() .hashString( getEmail() + System.currentTimeMillis() + hashCode() + new Random(System.currentTimeMillis()).nextGaussian(), Charsets.UTF_8).toString(); setConfirmationCode(confirmationCode); return FenixEduAcademicConfiguration.getConfiguration().getGenericApplicationEmailConfirmationLink() + confirmationCode + "&applicationExternalId=" + getExternalId(); }
public void testSha512() { HashTestUtils.checkAvalanche(Hashing.sha512(), 100, 0.4); HashTestUtils.checkNo2BitCharacteristics(Hashing.sha512()); HashTestUtils.checkNoFunnels(Hashing.sha512()); HashTestUtils.assertInvariants(Hashing.sha512()); assertEquals("Hashing.sha512()", Hashing.sha512().toString()); }
@Description("compute sha512 hash") @ScalarFunction @SqlType(StandardTypes.VARBINARY) public static Slice sha512(@SqlType(StandardTypes.VARBINARY) Slice slice) { return Slices.wrappedBuffer(Hashing.sha512().hashBytes(slice.getBytes()).asBytes()); }
@Description("compute sha512 hash") @ScalarFunction @SqlType(StandardTypes.VARBINARY) public static Slice sha512(@SqlType(StandardTypes.VARBINARY) Slice slice) { return Slices.wrappedBuffer(Hashing.sha512().hashBytes(slice.getBytes()).asBytes()); }
@Description("compute sha512 hash") @ScalarFunction @SqlType(StandardTypes.VARBINARY) public static Slice sha512(@SqlType(StandardTypes.VARBINARY) Slice slice) { return Slices.wrappedBuffer(Hashing.sha512().hashBytes(slice.getBytes()).asBytes()); }
public void testToString() { assertEquals("Hashing.md5()", Hashing.md5().toString()); assertEquals("Hashing.sha1()", Hashing.sha1().toString()); assertEquals("Hashing.sha256()", Hashing.sha256().toString()); assertEquals("Hashing.sha512()", Hashing.sha512().toString()); }