use of com.google.common.hash.HashCode in project che by eclipse.
the class PBKDF2PasswordEncryptor method encrypt.
@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);
}
use of com.google.common.hash.HashCode in project che by eclipse.
the class SHA512PasswordEncryptor method encrypt.
@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();
}
use of com.google.common.hash.HashCode in project buck by facebook.
the class TargetsCommand method processTargetHash.
private void processTargetHash(BuildTarget buildTarget, Map<BuildTarget, ShowOptions.Builder> showRulesResult, ImmutableMap<BuildTarget, HashCode> finalHashes) {
ShowOptions.Builder showOptionsBuilder = getShowOptionBuilder(showRulesResult, buildTarget);
HashCode hashCode = getHashCodeOrThrow(finalHashes, buildTarget);
showOptionsBuilder.setTargetHash(hashCode.toString());
}
use of com.google.common.hash.HashCode in project buck by facebook.
the class AutodepsWriter method writeSignedFile.
/**
* Writes the file only if the contents are different to avoid creating noise for Watchman/buckd.
* @param deps Keys must be sorted so the output is generated consistently.
* @param includeSignature Whether to insert a signature for the contents of the file.
* @param generatedFile Where to write the generated output.
* @param mapper To aid in JSON serialization.
* @return whether the file was written
*/
private static boolean writeSignedFile(SortedMap<String, SortedMap<String, Iterable<String>>> deps, boolean includeSignature, Path generatedFile, ObjectMapper mapper) throws IOException {
try (ByteArrayOutputStream bytes = new ByteArrayOutputStream();
HashingOutputStream hashingOutputStream = new HashingOutputStream(Hashing.sha1(), bytes)) {
ObjectWriter jsonWriter = mapper.writer(PRETTY_PRINTER.get());
jsonWriter.writeValue(includeSignature ? hashingOutputStream : bytes, deps);
// Flush a trailing newline through the HashingOutputStream so it is included both the
// output and the signature calculation.
hashingOutputStream.write('\n');
String serializedJson = bytes.toString(Charsets.UTF_8.name());
String contentsToWrite;
if (includeSignature) {
HashCode hash = hashingOutputStream.hash();
contentsToWrite = String.format(AUTODEPS_CONTENTS_FORMAT_STRING, hash, serializedJson);
} else {
contentsToWrite = serializedJson;
}
// to indiscriminately invalidate any cached build rules for the associated build file.
if (generatedFile.toFile().isFile()) {
String existingContents = com.google.common.io.Files.toString(generatedFile.toFile(), Charsets.UTF_8);
if (contentsToWrite.equals(existingContents)) {
return false;
}
}
try (Writer writer = Files.newBufferedWriter(generatedFile, Charsets.UTF_8)) {
writer.write(contentsToWrite);
}
return true;
}
}
use of com.google.common.hash.HashCode in project buck by facebook.
the class RuleKeyTest method createEmptyRuleKey.
private RuleKeyBuilder<RuleKeyResult<RuleKey>> createEmptyRuleKey(SourcePathResolver resolver, SourcePathRuleFinder ruleFinder) {
FileHashCache fileHashCache = new FileHashCache() {
@Override
public void invalidate(Path path) {
}
@Override
public void invalidateAll() {
}
@Override
public HashCode get(Path path) {
return HashCode.fromString("deadbeef");
}
@Override
public HashCode get(ArchiveMemberPath archiveMemberPath) {
return HashCode.fromString("deadbeef");
}
@Override
public long getSize(Path path) {
return 0;
}
@Override
public void set(Path path, HashCode hashCode) {
}
};
BuildTarget buildTarget = BuildTargetFactory.newInstance("//some:example");
BuildRule buildRule = new FakeBuildRule(buildTarget, resolver);
return new DefaultRuleKeyFactory(0, fileHashCache, resolver, ruleFinder).newBuilderForTesting(buildRule);
}
Aggregations