List of usage examples for com.google.common.hash Hashing sha512
public static HashFunction sha512()
From source file:com.tfgridiron.crowdsource.cmdline.ArchiveCreator.java
public String checksumFileCollection(SpreadsheetIndexer spreadsheetIndexer, Set<SpreadsheetMetadata> includedMetadata) { Set<String> allChecksums = new TreeSet<String>(); for (SpreadsheetMetadata m : includedMetadata) { allChecksums.add(m.getChecksum()); }//from w w w .ja v a 2 s. c o m Hasher hasher = Hashing.sha512().newHasher(); for (String checksum : allChecksums) { hasher.putString(checksum); } return hasher.hash().toString(); }
From source file:org.smartdeveloperhub.vocabulary.language.lexvo.LexvoDataSource.java
private Model loadModel(final String version, final Path input) throws IOException { final byte[] rawData = readInput(input); final String data = stringifyRawData(rawData); final Model model = parseRDF(data); this.lexvoVersion = version; this.lexvoSha256 = Hashing.sha256().hashBytes(rawData).toString(); this.lexvoSha512 = Hashing.sha512().hashBytes(rawData).toString(); return model; }
From source file:org.fim.model.State.java
public String hashState() { HashFunction hashFunction = Hashing.sha512(); Hasher hasher = hashFunction.newHasher(Constants._10_MB); hashObject(hasher);//from ww w .j a v a2 s .c om HashCode hash = hasher.hash(); return hash.toString(); }
From source file:org.fenixedu.bennu.core.domain.User.java
public void changePassword(final String password) { if (getPassword() != null) { String newHashWithOldSalt = Hashing.sha512().hashString(getSalt() + password, Charsets.UTF_8) .toString();/*from www. j a v a 2 s .c o m*/ if (newHashWithOldSalt.equals(getPassword())) { throw BennuCoreDomainException.badOldPassword(); } } byte salt[] = new byte[64]; prng.nextBytes(salt); setSalt(BaseEncoding.base64().encode(salt)); String hash = Hashing.sha512().hashString(getSalt() + password, Charsets.UTF_8).toString(); setPassword(hash); }
From source file:org.fenixedu.bennu.core.domain.User.java
public boolean matchesPassword(final String password) { if (getPassword() == null) { return true; }/* w ww . java 2 s. c om*/ final String hash = Hashing.sha512().hashString(getSalt() + password, Charsets.UTF_8).toString(); return hash.equals(getPassword()); }
From source file:io.prestosql.operator.scalar.VarbinaryFunctions.java
@Description("compute sha512 hash") @ScalarFunction/*from w w w .jav a 2 s . c o m*/ @SqlType(StandardTypes.VARBINARY) public static Slice sha512(@SqlType(StandardTypes.VARBINARY) Slice slice) { return Slices.wrappedBuffer(Hashing.sha512().hashBytes(slice.getBytes()).asBytes()); }
From source file:org.protelis.lang.ProtelisLoader.java
/** * @param program// w w w . j a v a 2 s.c om * the program in String format * @return a dummy:/ resource that can be used to interpret the program */ public static Resource resourceFromString(final String program) { final URI uri = URI.createURI("dummy:/protelis-generated-program-" + Hashing.sha512().hashString(program, StandardCharsets.UTF_8) + ".pt"); synchronized (XTEXT) { Resource r = XTEXT.get().getResource(uri, false); if (r == null) { try (InputStream in = new StringInputStream(program)) { loadStringResources(XTEXT.get(), in); } catch (IOException e) { throw new IllegalStateException("Couldn't get resources associated with anonymous program", e); } r = XTEXT.get().createResource(uri); try (InputStream in = new StringInputStream(program)) { r.load(in, XTEXT.get().getLoadOptions()); } catch (IOException e) { throw new IllegalStateException("I/O error while reading in RAM: this must be tough.", e); } } return r; } }
From source file:com.infinities.keystone4j.utils.Cms.java
public String hashToken(String tokenid, Algorithm mode) throws UnsupportedEncodingException, NoSuchAlgorithmException, DecoderException { if (mode == null) { mode = Algorithm.md5;/*from www . j a v a2s .co m*/ } if (Strings.isNullOrEmpty(tokenid)) { throw new NullPointerException("invalid tokenid"); } if (isAsn1Token(tokenid) || isPkiz(tokenid)) { HashFunction hf = Hashing.md5(); if (mode == Algorithm.sha1) { hf = Hashing.sha1(); } else if (mode == Algorithm.sha256) { hf = Hashing.sha256(); } else if (mode == Algorithm.sha512) { hf = Hashing.sha512(); } HashCode hc = hf.newHasher().putString(tokenid).hash(); return toHex(hc.asBytes()); } else { return tokenid; } }
From source file:net.sf.diningout.content.SyncAdapter.java
/** * Insert new system contacts, delete orphaned app contacts, and synchronise any changes to * existing./*from www. ja v a 2 s . c om*/ */ private void refreshContacts(Context context, ContentProviderClient cp) throws RemoteException { /* get system contacts */ String[] proj = { Email.ADDRESS, ContactsContract.Contacts.LOOKUP_KEY, RawContacts.CONTACT_ID, ContactsContract.Contacts.DISPLAY_NAME }; String sel = Email.IN_VISIBLE_GROUP + " = 1 AND " + Email.ADDRESS + " <> ?"; String[] args = { Accounts.selected().name }; EasyCursor sys = new EasyCursor(cr().query(Email.CONTENT_URI, proj, sel, args, Email.ADDRESS)); /* get app contacts */ proj = new String[] { Contacts.EMAIL, Contacts.ANDROID_LOOKUP_KEY, Contacts.ANDROID_ID, Contacts.NAME, _ID, Contacts.FOLLOWING, Contacts.STATUS_ID }; sel = Contacts.EMAIL + " IS NOT NULL"; EasyCursor app = new EasyCursor(cp.query(CONTACTS_URI, proj, sel, null, Contacts.EMAIL)); /* compare and sync */ ContentValues vals = new ContentValues(); for (CursorJoiner.Result result : new CursorJoiner(sys, new String[] { Email.ADDRESS }, app, new String[] { Contacts.EMAIL })) { switch (result) { case LEFT: // new system contact, insert into app contacts String email = sys.getString(Email.ADDRESS); String hash = BaseEncoding.base64() .encode(Hashing.sha512().hashString(email.toLowerCase(ENGLISH), UTF_8).asBytes()); long id = Contacts.idForHash(hash); // do we have this contact and not know it? /* insert or update values */ vals.put(Contacts.ANDROID_LOOKUP_KEY, sys.getString(ContactsContract.Contacts.LOOKUP_KEY)); vals.put(Contacts.ANDROID_ID, sys.getLong(RawContacts.CONTACT_ID)); String name = sys.getString(ContactsContract.Contacts.DISPLAY_NAME); vals.put(Contacts.NAME, name); vals.put(Contacts.NORMALISED_NAME, SQLite.normalise(name)); vals.put(Contacts.EMAIL, email); if (id <= 0) { vals.put(Contacts.EMAIL_HASH, hash); vals.put(Contacts.COLOR, Contacts.defaultColor()); id = ContentUris.parseId(cp.insert(CONTACTS_URI, vals)); } else { cp.update(ContentUris.withAppendedId(CONTACTS_URI, id), vals, null, null); } if (id > 0) { context.startService(new Intent(context, FriendColorService.class) .putExtra(FriendColorService.EXTRA_ID, id)); } break; case RIGHT: // orphaned app contact, delete unless user is following if (app.getInt(Contacts.FOLLOWING) == 0 && app.getInt(Contacts.STATUS_ID) == ACTIVE.id) { vals.put(Contacts.STATUS_ID, DELETED.id); vals.put(Contacts.DIRTY, 1); cp.update(Uris.appendId(CONTACTS_URI, app), vals, null, null); } break; case BOTH: // matching contacts, update details in app if needed String s = sys.getString(ContactsContract.Contacts.LOOKUP_KEY); if (!s.equals(app.getString(Contacts.ANDROID_LOOKUP_KEY))) { vals.put(Contacts.ANDROID_LOOKUP_KEY, s); } long l = sys.getLong(RawContacts.CONTACT_ID); if (l != app.getLong(Contacts.ANDROID_ID)) { vals.put(Contacts.ANDROID_ID, l); } s = sys.getString(ContactsContract.Contacts.DISPLAY_NAME); if (!s.equals(app.getString(Contacts.NAME))) { vals.put(Contacts.NAME, s); vals.put(Contacts.NORMALISED_NAME, SQLite.normalise(s)); } if (app.getInt(Contacts.STATUS_ID) == DELETED.id) { vals.put(Contacts.STATUS_ID, ACTIVE.id); vals.put(Contacts.DIRTY, 1); } if (vals.size() > 0) { cp.update(Uris.appendId(CONTACTS_URI, app), vals, null, null); context.startService(new Intent(context, FriendColorService.class) .putExtra(FriendColorService.EXTRA_ID, app.getLong(_ID))); } break; } vals.clear(); } sys.close(); app.close(); }
From source file:com.tfgridiron.crowdsource.cmdline.SpreadsheetIndexer.java
public String calculateWorksheetChecksum(WorksheetEntry playByPlayWorksheet, List<String> isDoneInfo) throws Exception { CellFeed cellFeed = apiUtils.getSpreadsheetService().getFeed(playByPlayWorksheet.getCellFeedUrl(), CellFeed.class); Hasher hasher = Hashing.sha512().newHasher(); for (CellEntry cell : cellFeed.getEntries()) { hasher.putString(cell.getId());// ww w . j a va2 s .c o m hasher.putString(cell.getCell().getValue()); } for (String doneInfo : isDoneInfo) { if (doneInfo != null) { hasher.putString(doneInfo); } else { hasher.putString(""); } } return hasher.hash().toString(); }