List of usage examples for com.google.common.hash Hashing sha256
public static HashFunction sha256()
From source file:org.apache.servicecomb.common.javassist.JavassistUtils.java
@SuppressWarnings("rawtypes") public static Class<? extends Enum> getOrCreateEnumWithPackageName(ClassLoader classLoader, String packageName, List<String> enums) { String strEnums = enums.toString(); String enumClsName = packageName + ".Enum_" + Hashing.sha256().hashString(strEnums, StandardCharsets.UTF_8).toString(); return JavassistUtils.getOrCreateEnumWithClassName(classLoader, enumClsName, enums); }
From source file:org.fenixedu.cms.domain.CMSThemeFiles.java
private String computeChecksum() { StringBuilder builder = new StringBuilder(); this.files.values().forEach(file -> { builder.append(Hashing.sha256().hashBytes(file.getContent()).toString()); });/* w w w. ja v a 2 s .c o m*/ return Hashing.murmur3_128().hashString(builder, StandardCharsets.UTF_8).toString().substring(0, 16); }
From source file:org.adho.dhconvalidator.conftool.ConfToolClient.java
private String getPassHash(String nonce) { return Hashing.sha256().hashString(nonce + new String(restSharedPass), Charsets.UTF_8).toString(); }
From source file:io.github.runassudo.gtfs.ZipStreamGTFSFile.java
public FlatGTFSFile toFlatFile() throws IOException { File destBase = new File( new File(GTFSCollection.cacheDir, Hashing.sha256().hashString(parentFile.getName(), StandardCharsets.UTF_8).toString()), Hashing.sha256().hashString(zipEntry.getName(), StandardCharsets.UTF_8).toString()); if (!destBase.exists()) { ZipArchiveInputStream gtfsStream = new ZipArchiveInputStream(parentFile.getInputStream(zipEntry)); ZipArchiveEntry contentEntry;//w w w. j av a 2 s . c om while ((contentEntry = gtfsStream.getNextZipEntry()) != null) { // Copy this file to cache File dest = new File(destBase, contentEntry.getName()); dest.getParentFile().mkdirs(); FileOutputStream os = new FileOutputStream(dest); byte[] buf = new byte[4096]; int len; while ((len = gtfsStream.read(buf)) > 0) { os.write(buf, 0, len); } os.close(); } gtfsStream.close(); } return new FlatGTFSFile(destBase); }
From source file:org.sfs.encryption.impl.SAES256v01.java
public SAES256v01(byte[] secretBytes, byte[] salt) { this.salt = salt.clone(); secretBytes = secretBytes.clone();//from ww w. java2s .c o m if (secretBytes.length != KEY_SIZE_BYTES) { secretBytes = Hashing.sha256().hashBytes(secretBytes).asBytes(); } try { KeyParameter key = new KeyParameter(secretBytes); AEADParameters params = new AEADParameters(key, MAC_SIZE_BITS, this.salt); this.encryptor = new GCMBlockCipher(new AESFastEngine()); this.encryptor.init(true, params); this.decryptor = new GCMBlockCipher(new AESFastEngine()); this.decryptor.init(false, params); } catch (Exception e) { throw new RuntimeException("could not create cipher for AES256", e); } finally { Arrays.fill(secretBytes, (byte) 0); } }
From source file:org.jclouds.glacier.util.TreeHash.java
private static HashCode hashList(Collection<HashCode> hashList) { Builder<HashCode> result = ImmutableList.builder(); while (hashList.size() > 1) { //Hash pairs of values and add them to the result list. for (Iterator<HashCode> it = hashList.iterator(); it.hasNext();) { HashCode hc1 = it.next();//from w ww .j a v a 2 s . co m if (it.hasNext()) { HashCode hc2 = it.next(); result.add(Hashing.sha256().newHasher().putBytes(hc1.asBytes()).putBytes(hc2.asBytes()).hash()); } else { result.add(hc1); } } hashList = result.build(); result = ImmutableList.builder(); } return hashList.iterator().next(); }
From source file:org.jclouds.glacier.util.AWSRequestSignerV4.java
private static HashCode buildHashedCanonicalRequest(String method, String endpoint, HashCode hashedPayload, String canonicalizedHeadersString, String signedHeaders) { return Hashing.sha256().newHasher().putString(method, UTF_8).putString("\n", UTF_8) .putString(endpoint, UTF_8).putString("\n", UTF_8).putString("\n", UTF_8) .putString(canonicalizedHeadersString, UTF_8).putString("\n", UTF_8).putString(signedHeaders, UTF_8) .putString("\n", UTF_8).putString(hashedPayload.toString(), UTF_8).hash(); }
From source file:it.anyplace.sync.core.cache.FileBlockCache.java
@Override public String pushBlock(final byte[] data) { String code = BaseEncoding.base16().encode(Hashing.sha256().hashBytes(data).asBytes()); return pushData(code, data) ? code : null; }
From source file:org.apache.rya.indexing.pcj.fluo.app.query.StatementPatternIdManager.java
/** * Add specified Set of ids to the Fluo table with Column {@link FluoQueryColumns#STATEMENT_PATTERN_IDS}. Also * updates the hash of the updated nodeId Set and writes that to the Column * {@link FluoQueryColumns#STATEMENT_PATTERN_IDS_HASH} * * @param tx - Fluo Transaction object for performing atomic operations on Fluo table. * @param ids - ids to add to the StatementPattern nodeId Set *///from www .j av a 2 s. c o m public static void addStatementPatternIds(TransactionBase tx, Set<String> ids) { checkNotNull(tx); checkNotNull(ids); Optional<Bytes> val = Optional.fromNullable(tx.get(Bytes.of(STATEMENT_PATTERN_ID), STATEMENT_PATTERN_IDS)); StringBuilder builder = new StringBuilder(); if (val.isPresent()) { builder.append(val.get().toString()); builder.append(VAR_DELIM); } String idString = builder.append(Joiner.on(VAR_DELIM).join(ids)).toString(); tx.set(Bytes.of(STATEMENT_PATTERN_ID), STATEMENT_PATTERN_IDS, Bytes.of(idString)); tx.set(Bytes.of(STATEMENT_PATTERN_ID), STATEMENT_PATTERN_IDS_HASH, Bytes.of(Hashing.sha256().hashString(idString).toString())); }
From source file:com.ea.promed.beans.DoctorBean.java
public String createDoctor() throws MessagingException, UnsupportedEncodingException { if (doctor.getId() != null) { Doctor eDoctor = (Doctor) sessionMap.get("eDoctor"); doctor.setUser(eDoctor.getUser()); doctorFacade.edit(doctor);/*from w w w . j a va 2 s. co m*/ sessionMap.put("message", "Doctor Info updated Successfully."); } else { String code = UUID.randomUUID().toString(); String hash = Hashing.sha256().hashString(code, Charsets.UTF_8).toString(); doctor.getUser().setVerification(hash); doctor.getUser().setPassword(hash); doctorFacade.create(doctor); userFacade.activateUser(doctor.getUser(), 2); emailBean.setToemail(doctor.getUser().getEmail()); emailBean.setSubject("Login Credentials : Pro Medical Services"); emailBean.setMessagetext(doctor.getFirstName(), "Your user name is " + doctor.getUser().getUsername() + ". You can create new password by clicking below link.", hash); emailBean.sendEMail(); sessionMap.put("message", "Doctor Info added Successfully."); } return "doctors?faces-redirect=true"; }