List of usage examples for org.apache.commons.codec.digest DigestUtils sha1
public static byte[] sha1(String data)
From source file:Main.java
public static byte[] multiSha(byte[] data) { byte[] res = DigestUtils.sha1(data); int headLength = res.length / 2; byte[] head = new byte[headLength]; if (res.length > headLength) { byte[] tail = new byte[res.length - headLength]; System.arraycopy(res, 0, head, 0, headLength); System.arraycopy(res, headLength, tail, 0, tail.length); head = DigestUtils.sha1(head);//from w w w .j ava 2 s .c o m tail = DigestUtils.sha1(tail); res = new byte[head.length + tail.length]; System.arraycopy(head, 0, res, 0, head.length); System.arraycopy(tail, 0, res, head.length, tail.length); } res = DigestUtils.sha1(res); return res; }
From source file:name.martingeisse.phunky.runtime.builtin.string.hash.Sha1Function.java
@Override protected byte[] hash(final byte[] data) { return DigestUtils.sha1(data); }
From source file:com.liferay.sync.engine.lan.util.LanTokenUtil.java
public static String createEncryptedToken(String lanTokenKey) throws Exception { String lanToken = RandomStringUtils.random(32, 0, 0, true, true, null, _secureRandom); byte[] bytes = DigestUtils.sha1(lanTokenKey); bytes = Arrays.copyOf(bytes, 16); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(bytes, "AES")); String encryptedToken = Base64 .encodeBase64String(cipher.doFinal(lanToken.getBytes(Charset.forName("UTF-8")))); _lanTokens.add(lanToken);//from w w w . ja va 2 s .c o m return encryptedToken; }
From source file:com.liferay.sync.engine.util.FileUtil.java
public static String getChecksum(Path filePath) throws IOException { if (!Files.exists(filePath) || (Files.size(filePath) > PropsValues.SYNC_FILE_CHECKSUM_THRESHOLD_SIZE)) { return ""; }//from ww w. j a v a2 s . c om InputStream fileInputStream = null; try { fileInputStream = Files.newInputStream(filePath); byte[] bytes = DigestUtils.sha1(fileInputStream); return Base64.encodeBase64String(bytes); } finally { StreamUtil.cleanUp(fileInputStream); } }
From source file:com.vmware.o11n.plugin.crypto.service.CryptoDigestService.java
public String sha1(String data) { return Base64.encodeBase64String(DigestUtils.sha1(data)); }
From source file:com.liferay.sync.engine.lan.util.LanTokenUtil.java
public static String decryptLanToken(String lanTokenKey, String encryptedToken) throws Exception { byte[] bytes = DigestUtils.sha1(lanTokenKey); bytes = Arrays.copyOf(bytes, 16); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(bytes, "AES")); return new String(cipher.doFinal(Base64.decodeBase64(encryptedToken)), Charset.forName("UTF-8")); }
From source file:com.vmware.o11n.plugin.crypto.service.CryptoDigestService.java
public String sha1Base64(String dataB64) { validateB64(dataB64); return Base64.encodeBase64String(DigestUtils.sha1(Base64.decodeBase64(dataB64))); }
From source file:net.morimekta.idltool.IdlUtils.java
private static File getCacheDirectory(File cacheDir, String repository) throws IOException { if (!cacheDir.exists()) { if (!cacheDir.mkdirs()) { throw new IOException( "Unable to create cache directory " + cacheDir.getCanonicalFile().getAbsolutePath()); }//from w w w. j a v a2 s . co m } String hash = Base64.getUrlEncoder() .encodeToString(DigestUtils.sha1(repository.getBytes(StandardCharsets.UTF_8))); return new File(cacheDir, hash).getCanonicalFile().getAbsoluteFile(); }
From source file:de.micromata.genome.gwiki.auth.PasswordUtils.java
public static String encodePassword(String salt, String clearPassword) { String encPwd = salt + Converter.encodeBase64(DigestUtils.sha1(salt + clearPassword)); return salt + encPwd; }
From source file:com.thoughtworks.go.util.FileUtil.java
public static String filesystemSafeFileHash(File folder) { String hash = Base64.getEncoder().encodeToString(DigestUtils.sha1(folder.getAbsolutePath().getBytes())); hash = hash.replaceAll("[^0-9a-zA-Z\\.\\-]", ""); return hash;// w ww .j a v a 2 s. c o m }