List of usage examples for org.apache.commons.codec.digest DigestUtils sha
@Deprecated public static byte[] sha(String data)
From source file:AddSHA1.java
public static void main(String args[]) { //1d5e6de6782a0406b4f49690d2849cf3c8365156 //System.out.println(DigestUtils.shaHex("1397553651725919662weixin")); //signature:1d5e6de6782a0406b4f49690d2849cf3c8365156,timestamp:1397612997,nonce:57092655,echostr:3405473746965751253 byte[] digest = DigestUtils.sha("1397553651725919662weixin"); String outStr = bytetoString(digest); System.out.println(outStr);//from w ww.ja v a2 s . c o m System.out.println(DigestUtils.shaHex("1397553651725919662weixin")); System.out.println(SHA1("1397553651725919662weixin")); }
From source file:DigestUsage.java
public void start() { String hashData = "Hello World!!"; System.err.println("Hello World!! as MD5 16 element hash: " + new String(DigestUtils.md5(hashData))); System.err.println("Hello World!! as MD5 Hex hash: " + DigestUtils.md5Hex(hashData)); System.err.println("Hello World!! as SHA byte array hash: " + new String(DigestUtils.sha(hashData))); System.err.println("Hello World!! as SHA Hex hash: " + DigestUtils.shaHex(hashData)); }
From source file:com.emarsys.predict.StringUtil.java
/** * Calculates the SHA-1 digest and returns the value as String * * @param s data to digest/*from ww w . ja va2 s . c om*/ * @return SHA-1 digest */ static String sha1(String s) { return new String(Hex.encodeHex(DigestUtils.sha(s))); }
From source file:com.mirth.connect.server.util.Pre22PasswordChecker.java
/** * The pre-2.2 password has been migrated to the following * format://w ww .j ava2 s . c om * * SALT_ + 8-bit salt + base64(sha(salt + password)) * * To compare: * * 1. Strip the known pre-2.2 prefix * 2. Get the first 8-bits and Base64 decode it, this the salt * 3. Get the remaining bits and Base64 decode it, this is the hash * 4. Pass it into the pre-2.2 password checker algorithm * * @param plainPassword The plain text password to check against the hash * @param encodedPassword The hashed password * @return true if the password matches the hash using the pre-2.2 algorithm, false otherwise */ public static boolean checkPassword(String plainPassword, String encodedPassword) throws Exception { String saltHash = StringUtils.substringAfter(encodedPassword, SALT_PREFIX); String encodedSalt = StringUtils.substring(saltHash, 0, SALT_LENGTH); byte[] decodedSalt = Base64.decodeBase64(encodedSalt); byte[] decodedHash = Base64.decodeBase64(StringUtils.substring(saltHash, encodedSalt.length())); if (Arrays.equals(decodedHash, DigestUtils.sha(ArrayUtils.addAll(decodedSalt, plainPassword.getBytes())))) { return true; } return false; }
From source file:com.simplymeasured.hive.UDFSHA1Hash.java
public String evaluate(String valueToHash) { return Hex.encodeHexString(DigestUtils.sha(valueToHash)); }
From source file:edu.umn.msi.tropix.storage.core.access.fs.DirectoryTreeFileFunctionImpl.java
public File apply(final String id) { byte[] bytes = id.getBytes(); File binDirectory = directory; for (int currentDepth = 0; currentDepth < depth; currentDepth++) { bytes = DigestUtils.sha(bytes); binDirectory = new File(binDirectory, encode(bytes, width)); }/*www . j av a 2s . c om*/ return new File(binDirectory, id); }
From source file:edu.umn.msi.tropix.client.authentication.impl.LocalUserManagerImpl.java
private String hash(final String password) { return new String(Base64.encodeBase64(DigestUtils.sha(password))); }
From source file:monasca.api.domain.model.dimension.DimensionValues.java
private String generateId() { String hashstr = "metricName=" + metricName + "dimensionName=" + dimensionName; byte[] sha1Hash = DigestUtils.sha(hashstr); return Hex.encodeHexString(sha1Hash); }
From source file:edu.psu.citeseerx.utility.FileDigest.java
/** * Calculates a file's SHA1 digest and returns it as a <code>byte[]</code>. * @param toDigest Data to digest/*from w w w.ja v a 2 s .c o m*/ * @return SHA1 digest */ public static byte[] sha1(File toDigest) { byte[] fileContent = getFileContent(toDigest); return DigestUtils.sha(fileContent); }
From source file:be.fedict.eid.pkira.portal.signing.AbstractDssSigningHandler.java
public String handleDssRequest() { String redirectStatus = null; T serviceClientResponse = null;//from w w w. jav a2s .c om try { // Extract the signature response String signatureRequestId = "request-" + java.util.UUID.randomUUID().toString(); SignatureResponse signatureResponse = signatureResponseProcessor.process(getRequest(), getTarget(), getBase64encodedSignatureRequest(), signatureRequestId, null); // Get dssCertificate digest and allowed fingerprints String actualServiceFingerprint = null; String serviceCertificate = getRequest() .getParameter(SignatureResponseProcessor.SERVICE_CERTIFICATE_PARAMETER_PREFIX + "1"); if (serviceCertificate != null) { byte[] certificateData = Base64.decodeBase64(serviceCertificate); byte[] certificateFingerPrint = DigestUtils.sha(certificateData); actualServiceFingerprint = Hex.encodeHexString(certificateFingerPrint); } log.info("Actual service fingerprint: " + actualServiceFingerprint); String[] fingerprintConfig = configurationEntryContainer.getDssFingerprints(); if (fingerprintConfig == null || fingerprintConfig.length == 0) { log.warn("No DSS fingerprints configured"); } else { if (actualServiceFingerprint == null) { log.warn("No dssCertificate in DSS response"); throw new SecurityException("Missing dssCertificate in DSS response"); } boolean ok = false; for (String fingerprint : fingerprintConfig) { log.info("Allowed service fingerprint: " + fingerprint); ok |= fingerprint != null && fingerprint.equalsIgnoreCase(actualServiceFingerprint); } if (!ok) { log.error("Signatures not correct."); throw new SecurityException("Signatures not correct."); } } // Call the contract service byte[] contract = signatureResponse.getDecodedSignatureResponse(); String result = invokeServiceClient(new String(contract)); serviceClientResponse = unmarshall(result); getFacesMessages().addFromResourceBundle("contract.status." + serviceClientResponse.getResult().name(), serviceClientResponse.getResultMessage()); if (Events.exists()) { Events.instance().raiseEvent(EVENT_CERTIFICATE_LIST_CHANGED); } if (ResultType.SUCCESS.equals(serviceClientResponse.getResult())) { redirectStatus = SUCCESSFUL_REDIRECT; } } catch (Exception e) { getFacesMessages().addFromResourceBundle("validator.error.sign"); log.info("<<< handleRequest: exception", e); } return handleRedirect(redirectStatus, serviceClientResponse); }