List of usage examples for org.apache.commons.codec.digest DigestUtils sha1Hex
public static String sha1Hex(String data)
From source file:com.plugins.pomfromjar.mojo.JarDependencyGenerator.java
/** * Iterate through jar files in dir (non recursive) and create the * corresponding dependencies/*w w w. ja v a 2s. c o m*/ * * Documentation available on * http://commons.apache.org/codec/apidocs/org/apache/commons/codec/digest/DigestUtils.html * An advanced maven search accepts a SHA-1 checksum - http://search.maven.org/#advancedsearch */ private void createDependenciesFromJarDir() throws IOException { String sha1; FileInputStream fileInputStream; path = new File(jarDir); LOGGER.info("JAR DIR : " + jarDir); File dir = new File(jarDir); for (File child : dir.listFiles()) { String fileName = child.getName(); if (child.isFile() && fileName.endsWith(".jar")) { fileInputStream = new FileInputStream(child); sha1 = DigestUtils.sha1Hex(fileInputStream); dependencyList.addDependency(fileName, repositoryUri, sha1); } } }
From source file:be.fedict.hsm.admin.webapp.security.AuthenticationController.java
public void login(ComponentSystemEvent event) { LOG.debug("login"); FacesContext facesContext = FacesContext.getCurrentInstance(); if (facesContext.getResponseComplete()) { return;/*from w w w.j a v a2 s .c o m*/ } if (null == this.authenticationCertificate) { /* * Caused by a direct navigation to post-login.jsf */ redirect(facesContext, "/index.xhtml"); return; } byte[] encodedCertificate; try { encodedCertificate = this.authenticationCertificate.getEncoded(); } catch (CertificateEncodingException e) { LOG.error("certificate encoding error: " + e.getMessage(), e); return; } /* * The challenged certificate is the unique user identifier. */ String username = DigestUtils.sha1Hex(encodedCertificate); String password = this.identity.getCardNumber(); ExternalContext externalContext = facesContext.getExternalContext(); HttpServletRequest httpServletRequest = (HttpServletRequest) externalContext.getRequest(); try { httpServletRequest.login(username, password); } catch (ServletException e) { LOG.error("login error: " + e.getMessage(), e); accessDenied(facesContext); return; } Principal userPrincipal = httpServletRequest.getUserPrincipal(); if (null == userPrincipal) { accessDenied(facesContext); return; } LOG.debug("user principal: " + userPrincipal.getName()); LOG.debug("admin role: " + httpServletRequest.isUserInRole(AdministratorRoles.ADMINISTRATOR)); if (false == httpServletRequest.isUserInRole(AdministratorRoles.ADMINISTRATOR)) { accessDenied(facesContext); return; } String targetViewId = SecurityPhaseListener.getTargetViewId(externalContext); redirect(facesContext, targetViewId); }
From source file:gr.demokritos.iit.security.SecurityLayer.java
/** * Password encryption. Calculates the SHA-1 digest and returns the value as * a hex string.//ww w. j av a 2s .c om * * @param password the password that we want to encrypt * @return */ public String encryptPassword(String password) { return DigestUtils.sha1Hex(password); }
From source file:com.machinepublishers.jbrowserdriver.HttpCache.java
/** * {@inheritDoc}/*from w w w . jav a2s. c o m*/ */ @Override public HttpCacheEntry getEntry(String key) throws IOException { try (Lock lock = new Lock(new File(cacheDir, DigestUtils.sha1Hex(key)), true, false)) { BufferedInputStream bufferIn = new BufferedInputStream(lock.streamIn); try (ObjectInputStream objectIn = new ObjectInputStream(bufferIn)) { return (HttpCacheEntry) objectIn.readObject(); } catch (Throwable t) { LogsServer.instance().exception(t); } } catch (FileNotFoundException e) { return null; } return null; }
From source file:com.wordpress.metaphorm.authProxy.state.UserToken.java
public boolean isUntampedWith() { String unhashed = this.intendedFor + ":" + this.companyId + ":" + this.scopeGroupId + ":" + this.userId + ":" + this.sessionIdHashed; String reHash = DigestUtils.sha1Hex(unhashed + ":" + secret); return (reHash.equals(this.hash)); }
From source file:com.vmware.o11n.plugin.crypto.service.CryptoCertificateService.java
/** * Get SHA1 fingerprint/thumbprint of a Certificate * Returns the fingerprint as a colon delimited hex string * * @param cert Certificate//from ww w. ja va 2 s . c o m * @return Hex encoded sha1 fingerprint of certificate * @throws CertificateException */ public String getSha1Fingerprint(Certificate cert) throws CertificateException { byte[] encoded = cert.getEncoded(); String certFinger = DigestUtils.sha1Hex(encoded); return fixFingerprintHex(certFinger); }
From source file:net.orzo.lib.Strings.java
/** * *//*from w w w . j av a2 s . c om*/ public Object hash(String value, String algorithm) { if (value == null) { throw new RuntimeException("null value not accepted in hash() function"); } switch (algorithm.toLowerCase()) { case "md5": return DigestUtils.md5Hex(value); case "sha1": return DigestUtils.sha1Hex(value); case "sha256": return DigestUtils.sha256Hex(value); case "sha384": return DigestUtils.sha384Hex(value); case "sha512": return DigestUtils.sha512Hex(value); default: throw new RuntimeException(String.format("Unknown hash function '%s'", algorithm)); } }
From source file:net.ftb.util.CryptoUtils.java
/** * method to pad AES keys by using the sha1Hex hash on them * @param key key to pad//w w w .j a v a2 s .co m * @return padded key */ public static byte[] pad(byte[] key) { try { return Arrays.copyOf(DigestUtils.sha1Hex(key).getBytes("utf8"), 16); } catch (UnsupportedEncodingException e) { Logger.logError("error encoding padded key!", e); return Arrays.copyOf(DigestUtils.sha1Hex(key).getBytes(), 16); } }
From source file:com.lr.backer.controller.Pay.java
/** * ??//from w ww . ja v a2 s . c o m * @param timestamp * @param noncestr * @param packages * @return * @throws UnsupportedEncodingException */ public static String paySign(String timestamp, String noncestr, String packages) throws UnsupportedEncodingException { Map<String, String> paras = new HashMap<String, String>(); paras.put("appid", ConfKit.get("AppId")); paras.put("timestamp", timestamp); paras.put("noncestr", noncestr); paras.put("package", packages); paras.put("appkey", ConfKit.get("paySignKey")); // appid?timestamp?noncestr?package ? appkey String string1 = createSign(paras, false); String paySign = DigestUtils.sha1Hex(string1); return paySign; }
From source file:at.stefanproell.ResultSetVerification.ResultSetVerificationAPI.java
/** * Calculate SHA1 hash from input//from w w w. j a v a 2s . com * * @param inputString * @return * @throws NoSuchAlgorithmException */ public String calculateSHA1HashFromString(String inputString) { try { this.crypto.update(inputString.getBytes("utf8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } String hash = DigestUtils.sha1Hex(this.crypto.digest()); return hash; }