Java Code Examples for com.google.common.hash.HashCode#fromBytes()
The following examples show how to use
com.google.common.hash.HashCode#fromBytes() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultResolver.java From emodb with Apache License 2.0 | 5 votes |
private HashCode parseHash(String string) { try { return HashCode.fromBytes(Hex.decodeHex(string.toCharArray())); } catch (DecoderException e) { throw Throwables.propagate(e); } }
Example 2
Source File: SHA512PasswordEncryptor.java From che with Eclipse Public License 2.0 | 5 votes |
@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(); }
Example 3
Source File: PBKDF2PasswordEncryptor.java From che with Eclipse Public License 2.0 | 5 votes |
@Override public String encrypt(String password) { requireNonNull(password, "Required non-null password"); final byte[] salt = new byte[SALT_LENGTH]; SECURE_RANDOM.nextBytes(salt); final HashCode hash = computeHash(password.toCharArray(), salt, ITERATIONS_COUNT); final HashCode saltHash = HashCode.fromBytes(salt); return format(PWD_FMT, hash, saltHash, ITERATIONS_COUNT); }
Example 4
Source File: PBKDF2PasswordEncryptor.java From che with Eclipse Public License 2.0 | 5 votes |
private HashCode computeHash(char[] password, byte[] salt, int iterations) { try { final SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(SECRET_KEY_FACTORY_NAME); final KeySpec keySpec = new PBEKeySpec(password, salt, iterations, 512); return HashCode.fromBytes(keyFactory.generateSecret(keySpec).getEncoded()); } catch (NoSuchAlgorithmException | InvalidKeySpecException x) { throw new RuntimeException(x.getMessage(), x); } }
Example 5
Source File: BloomFilter.java From presto-bloomfilter with Apache License 2.0 | 5 votes |
public static HashCode readHash(Slice s) { if (s == null) { return HASH_CODE_NOT_FOUND; } return HashCode.fromBytes(s.getBytes(0, 32)); }
Example 6
Source File: SQLiteArtifactCacheBenchmark.java From buck with Apache License 2.0 | 5 votes |
@BeforeExperiment private void setUpBenchmark() throws IOException, SQLException { artifactCache = cache(Optional.of(1024 * 1024 * 1024L)); byte[] randomRuleKey = new byte[16]; ruleKeys = new ArrayList<>(opCount); contentHashes = new ArrayList<>(opCount); metadataInfo = new ArrayList<>(opCount); contentInfo = new ArrayList<>(opCount); for (int i = 0; i < opCount; i++) { random.nextBytes(randomRuleKey); RuleKey ruleKey = new RuleKey(HashCode.fromBytes(randomRuleKey)); ruleKeys.add(ruleKey); metadataInfo.add( ArtifactInfo.builder() .addRuleKeys(ruleKey) .putMetadata(TwoLevelArtifactCacheDecorator.METADATA_KEY, "foo") .putMetadata(BuildInfo.MetadataKey.RULE_KEY, ruleKey.toString()) .putMetadata(BuildInfo.MetadataKey.TARGET, "bar") .build()); random.nextBytes(randomRuleKey); RuleKey contentHash = new RuleKey(HashCode.fromBytes(randomRuleKey)); contentHashes.add(contentHash); contentInfo.add(ArtifactInfo.builder().addRuleKeys(contentHash).build()); } }
Example 7
Source File: AbstractNonStreamingHashFunctionTest.java From zetasketch with Apache License 2.0 | 4 votes |
@Override public HashCode hashBytes(byte[] input, int off, int len) { return HashCode.fromBytes(Arrays.copyOfRange(input, off, off + len)); }
Example 8
Source File: ModelUtils.java From presto with Apache License 2.0 | 4 votes |
public static HashCode modelHash(Slice slice) { return HashCode.fromBytes(slice.getBytes(HASH_OFFSET, 32)); }
Example 9
Source File: HashCodeCodec.java From bazel with Apache License 2.0 | 4 votes |
@Override public HashCode deserialize(DeserializationContext context, CodedInputStream codedIn) throws SerializationException, IOException { return HashCode.fromBytes(codedIn.readByteArray()); }