List of usage examples for com.google.common.hash HashCode fromString
@CheckReturnValue public static HashCode fromString(String string)
From source file:com.google.devtools.build.lib.remote.FakeActionInputFileCache.java
@Override @Nullable/*from www . j av a2s. c o m*/ public ActionInput getInputFromDigest(ByteString hexDigest) { HashCode code = HashCode.fromString(hexDigest.toStringUtf8()); ByteString digest = ByteString.copyFrom(code.asBytes()); return Preconditions.checkNotNull(cas.inverse().get(digest)); }
From source file:com.facebook.buck.core.rulekey.RuleKey.java
/** * @param hashString string that conforms to the contract of the return value of {@link * com.google.common.hash.HashCode#toString()}. */// ww w . j a v a2s .c o m public RuleKey(String hashString) { this(HashCode.fromString(hashString)); }
From source file:org.eclipse.che.security.SHA512PasswordEncryptor.java
@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; }//w w w .ja v a2 s. c o m 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); }
From source file:com.facebook.buck.util.cache.JarContentHasher.java
public ImmutableMap<Path, HashCodeAndFileType> getContentHashes() throws IOException { Manifest manifest = filesystem.getJarManifest(jarRelativePath); if (manifest == null) { throw new UnsupportedOperationException( "Cache does not know how to return hash codes for archive members except " + "when the archive contains a META-INF/MANIFEST.MF with " + HashingDeterministicJarWriter.DIGEST_ATTRIBUTE_NAME + " attributes for each file."); }//from w w w . j a v a 2 s. c o m ImmutableMap.Builder<Path, HashCodeAndFileType> builder = ImmutableMap.builder(); for (Map.Entry<String, Attributes> nameAttributesEntry : manifest.getEntries().entrySet()) { Path memberPath = Paths.get(nameAttributesEntry.getKey()); Attributes attributes = nameAttributesEntry.getValue(); String hashStringValue = attributes.getValue(HashingDeterministicJarWriter.DIGEST_ATTRIBUTE_NAME); if (hashStringValue == null) { continue; } HashCode memberHash = HashCode.fromString(hashStringValue); HashCodeAndFileType memberHashCodeAndFileType = HashCodeAndFileType.ofFile(memberHash); builder.put(memberPath, memberHashCodeAndFileType); } return builder.build(); }
From source file:com.facebook.buck.util.sha1.Sha1HashCode.java
public static Sha1HashCode of(String hash) { Preconditions.checkArgument(SHA1_PATTERN.matcher(hash).matches(), "Should be 40 lowercase hex chars: %s.", hash);/* ww w . j ava 2s .co m*/ // Note that this could be done with less memory if we created the byte[20] ourselves and // walked the string and converted the hex chars into bytes as we went. byte[] bytes = HashCode.fromString(hash).asBytes(); return fromBytes(bytes); }
From source file:com.facebook.buck.util.cache.impl.DefaultJarContentHasher.java
@Override public ImmutableMap<Path, HashCodeAndFileType> getContentHashes() throws IOException { Manifest manifest = filesystem.getJarManifest(jarRelativePath); if (manifest == null) { throw new UnsupportedOperationException( "Cache does not know how to return hash codes for archive members except " + "when the archive contains a META-INF/MANIFEST.MF with " + CustomJarOutputStream.DIGEST_ATTRIBUTE_NAME + " attributes for each file."); }/*from w w w . j ava 2s . c o m*/ ImmutableMap.Builder<Path, HashCodeAndFileType> builder = ImmutableMap.builder(); for (Map.Entry<String, Attributes> nameAttributesEntry : manifest.getEntries().entrySet()) { Path memberPath = Paths.get(nameAttributesEntry.getKey()); Attributes attributes = nameAttributesEntry.getValue(); String hashStringValue = attributes.getValue(CustomJarOutputStream.DIGEST_ATTRIBUTE_NAME); if (hashStringValue == null) { continue; } HashCode memberHash = HashCode.fromString(hashStringValue); HashCodeAndFileType memberHashCodeAndFileType = HashCodeAndFileType.ofFile(memberHash); builder.put(memberPath, memberHashCodeAndFileType); } return builder.build(); }
From source file:com.facebook.buck.rules.Manifest.java
/** * Deserialize an existing manifest from the given {@link InputStream}. *//*from w w w . java2 s.co m*/ public Manifest(InputStream rawInput) throws IOException { DataInputStream input = new DataInputStream(rawInput); Preconditions.checkState(input.readInt() == VERSION); int numberOfHeaders = input.readInt(); headers = new ArrayList<>(numberOfHeaders); headerIndices = new HashMap<>(numberOfHeaders); for (int index = 0; index < numberOfHeaders; index++) { String header = input.readUTF(); headers.add(header); headerIndices.put(header, index); } int numberOfHashes = input.readInt(); hashes = new ArrayList<>(numberOfHashes); hashIndices = new HashMap<>(numberOfHashes); for (int index = 0; index < numberOfHashes; index++) { int headerIndex = input.readInt(); HashCode headerHash = HashCode.fromString(input.readUTF()); hashes.add(new Pair<>(headerIndex, headerHash)); hashIndices.put(headerHash, index); } int numberOfEntries = input.readInt(); entries = new ArrayList<>(numberOfEntries); for (int entryIndex = 0; entryIndex < numberOfEntries; entryIndex++) { int numberOfEntryHashes = input.readInt(); int[] entryHashes = new int[numberOfEntryHashes]; for (int hashIndex = 0; hashIndex < numberOfEntryHashes; hashIndex++) { entryHashes[hashIndex] = input.readInt(); } RuleKey key = new RuleKey(input.readUTF()); entries.add(new Pair<>(key, entryHashes)); } }
From source file:org.eclipse.che.security.PBKDF2PasswordEncryptor.java
@Override public boolean test(String password, String encryptedPassword) { requireNonNull(password, "Required non-null password"); requireNonNull(password, "Required non-null encrypted password"); final Matcher matcher = PWD_REGEX.matcher(encryptedPassword); if (!matcher.matches()) { return false; }/* w ww . j a v a 2 s. co m*/ // retrieve salt, password hash and iterations count from hash final Integer iterations = tryParse(matcher.group("iterations")); final String salt = matcher.group("saltHash"); final String pwdHash = matcher.group("pwdHash"); // compute password's hash and test whether it matches to given hash final HashCode hash = computeHash(password.toCharArray(), HashCode.fromString(salt).asBytes(), iterations); return hash.toString().equals(pwdHash); }
From source file:de.siegmar.securetransfer.controller.ReceiveController.java
private void prepareMessage(final String id, final String linkSecret, final String password, final Model model, final HttpSession session) { final DecryptedMessage decryptedMessage = messageService.decryptAndBurnMessage(id, HashCode.fromString(linkSecret).asBytes(), password); model.addAttribute("decryptedMessage", decryptedMessage); // store iv to session to prevent download link "sharing" decryptedMessage.getFiles()//from w ww. ja va 2 s . com .forEach(f -> session.setAttribute(buildSessionAttr(f.getId()), f.getKeyIv().getIv())); }
From source file:com.facebook.buck.core.build.engine.manifest.Manifest.java
/** Deserialize an existing manifest from the given {@link InputStream}. */ public Manifest(InputStream rawInput) throws IOException { DataInputStream input = new DataInputStream(rawInput); // Verify the manifest version. int version = input.readInt(); Preconditions.checkState(version == VERSION, "invalid version: %s != %s", version, VERSION); key = new RuleKey(input.readUTF()); int numberOfHeaders = input.readInt(); LOG.verbose("%s: loading %d input entries", this.key, numberOfHeaders); inputs = new ArrayList<>(numberOfHeaders); inputIndices = new HashMap<>(numberOfHeaders); for (int index = 0; index < numberOfHeaders; index++) { String inputName = input.readUTF(); inputs.add(inputName);// ww w . j a v a 2s.c om inputIndices.put(inputName, index); } int numberOfHashes = input.readInt(); LOG.verbose("%s: loading %d hash entries", this.key, numberOfHashes); hashes = new ArrayList<>(numberOfHashes); hashIndices = new HashMap<>(numberOfHashes); for (int index = 0; index < numberOfHashes; index++) { int inputIndex = input.readInt(); HashCode inputHash = HashCode.fromString(input.readUTF()); hashes.add(new Pair<>(inputIndex, inputHash)); hashIndices.put(inputHash, index); } int numberOfEntries = input.readInt(); LOG.verbose("%s: loading %d dep file rule key entries", this.key, numberOfEntries); entries = new ArrayList<>(numberOfEntries); for (int entryIndex = 0; entryIndex < numberOfEntries; entryIndex++) { int numberOfEntryHashes = input.readInt(); int[] entryHashes = new int[numberOfEntryHashes]; for (int hashIndex = 0; hashIndex < numberOfEntryHashes; hashIndex++) { entryHashes[hashIndex] = input.readInt(); } RuleKey key = new RuleKey(input.readUTF()); LOG.verbose("%s: loaded entry for dep file rule key %s", this.key, key); entries.add(new Pair<>(key, entryHashes)); } }