List of usage examples for org.apache.commons.codec.binary Hex encodeHexString
public static String encodeHexString(byte[] data)
From source file:eu.europa.ec.markt.dss.signature.xades.XAdESProfileBES.java
/** * The ID of xades:SignedProperties is contained in the signed content of the xades Signature. We must create this * ID in a deterministic way. The signingDate and signingCertificate are mandatory in the more basic level of * signature, we use them as "seed" for generating the ID. * //from www .ja v a2 s . c om * @param params * @return */ String computeDeterministicId(SignatureParameters params) { try { MessageDigest digest = MessageDigest.getInstance("MD5"); digest.update(Long.toString(params.getSigningDate().getTime()).getBytes()); digest.update(params.getSigningCertificate().getEncoded()); String md5id = "id" + Hex.encodeHexString(digest.digest()); return md5id; } catch (NoSuchAlgorithmException ex) { LOG.severe(ex.getMessage()); throw new RuntimeException("MD5 Algorithm not found !"); } catch (CertificateEncodingException ex) { throw new RuntimeException("Certificate encoding exception"); } }
From source file:com.vmware.photon.controller.model.adapters.vsphere.ovf.OvfRetriever.java
private String hash(URI ovaOrOvfUri) { try {//from w w w . j a va 2 s . co m MessageDigest sha256 = MessageDigest.getInstance("SHA-1"); sha256.update(ovaOrOvfUri.toString().getBytes(Utils.CHARSET)); byte[] digest = sha256.digest(); return Hex.encodeHexString(digest); } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) { throw new RuntimeException(e); } }
From source file:com.aoppp.gatewaysdk.internal.hw.DigestUtils2.java
/** * Calculates the SHA-1 digest and returns the value as a hex string. * * @param data//ww w .j a v a 2s . co m * Data to digest * @return SHA-1 digest as a hex string * @since 1.7 */ public static String sha1Hex(final byte[] data) { return Hex.encodeHexString(sha1(data)); }
From source file:VerifyDescriptors.java
private static boolean verifySignature(String digest, String signature, String signingKey) throws Exception { byte[] signatureBytes = Base64.decodeBase64(signature.substring(0 + "-----BEGIN SIGNATURE-----\n".length(), signature.length() - "-----END SIGNATURE-----\n".length()).replaceAll("\n", "")); RSAPublicKey rsaSigningKey = (RSAPublicKey) new PEMReader(new StringReader(signingKey)).readObject(); RSAKeyParameters rsakp = new RSAKeyParameters(false, rsaSigningKey.getModulus(), rsaSigningKey.getPublicExponent()); PKCS1Encoding pe = new PKCS1Encoding(new RSAEngine()); pe.init(false, rsakp);//from w ww. j av a2 s . co m byte[] decryptedSignatureDigest = pe.processBlock(signatureBytes, 0, signatureBytes.length); String decryptedSignatureDigestString = Hex.encodeHexString(decryptedSignatureDigest); return decryptedSignatureDigestString.equalsIgnoreCase(digest); }
From source file:io.hawt.osgi.jmx.RBACDecorator.java
/** * Converts {@link ObjectName} to a key that helps verifying whether different MBeans can produce same RBAC info * @param allJmxAclPids//from ww w . ja v a2 s. c om * @param n * @return */ public static String pidListKey(List<String> allJmxAclPids, ObjectName n) throws NoSuchAlgorithmException, UnsupportedEncodingException { List<String> pidCandidates = iterateDownPids(nameSegments(n)); MessageDigest md = MessageDigest.getInstance("MD5"); for (String pc : pidCandidates) { String generalPid = getGeneralPid(allJmxAclPids, pc); if (generalPid.length() > 0) { md.update(generalPid.getBytes("UTF-8")); } } return Hex.encodeHexString(md.digest()); }
From source file:evm.RegisterFingerPrint.java
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed if (username.getText().isEmpty()) { JOptionPane.showMessageDialog(this, "Username is empty"); } else {//from w w w . j a va 2 s . co m DatabaseHandler databaseHandler = new DatabaseHandler(); //boolean bool = databaseHandler.addToDB(username.getText(), Hex.encodeHexString(fingerData.ANSITemplate()), Hex.encodeHexString(fingerData.ISOTemplate())); String arr[] = new String[10]; for (int i = 0; i < 10; i++) { arr[i] = Hex.encodeHexString(fdarr[i].ANSITemplate()); } boolean bool = databaseHandler.addToDB(username.getText(), arr); if (bool) { JOptionPane.showMessageDialog(this, "User is added successfully"); dispose(); } else JOptionPane.showMessageDialog(this, "Could not add data to DB"); } }
From source file:com.aoppp.gatewaysdk.internal.hw.DigestUtils2.java
/** * Calculates the SHA-1 digest and returns the value as a hex string. * * @param data//from ww w. ja v a 2s . co m * Data to digest * @return SHA-1 digest as a hex string * @throws IOException * On error reading from the stream * @since 1.7 */ public static String sha1Hex(final InputStream data) throws IOException { return Hex.encodeHexString(sha1(data)); }
From source file:at.gv.egiz.pdfas.lib.pki.impl.DefaultCertificateVerificationDataProvider.java
/** * Returns the signing certificate's authority key identifier entry (if any). * /*from w ww . j ava 2 s . c o m*/ * @param signingCertificate * The signing certificate (required; must not be {@code null}). * @return A hex string (lowercase) representing the authority key identifier (or {@code null} in case the * certificate does not have this extension or the extension could not be initialized). */ private String getAuthorityKeyIdentifierHexString(X509Certificate signingCertificate) { AuthorityKeyIdentifier aki; try { aki = (AuthorityKeyIdentifier) signingCertificate.getExtension(AuthorityKeyIdentifier.oid); } catch (X509ExtensionInitException e) { // go a defensive way, do not throw exception log.warn("Unable to initialize X.509 authority key identifier extension.", e); return null; } if (aki != null) { return Hex.encodeHexString(aki.getKeyIdentifier()); } return null; }
From source file:com.tremolosecurity.proxy.SessionManagerImpl.java
private HttpSession createSession(ApplicationType app, HttpServletRequest req, HttpServletResponse resp, ServletContext ctx, SecretKey encKey) throws Exception { byte[] idBytes = new byte[20]; random.nextBytes(idBytes);/*from w w w . j av a 2 s. c o m*/ StringBuffer b = new StringBuffer(); b.append('f').append(Hex.encodeHexString(idBytes)); String id = b.toString(); // HttpSession session = req.getSession(true); TremoloHttpSession tsession = new TremoloHttpSession(id); tsession.setAppName(app.getName()); tsession.refresh(this.ctx, this); tsession.setOpen(false); this.anonMech.createSession(tsession, this.anonChainType); AuthController actl = (AuthController) tsession.getAttribute(ProxyConstants.AUTH_CTL); AuthInfo auInfo = actl.getAuthInfo(); auInfo.setAuthComplete(true); // session.setAttribute(app.getCookieConfig().getSessionCookieName(), // tsession); tsession.setAttribute(OpenUnisonConstants.TREMOLO_SESSION_ID, id); tsession.setMaxInactiveInterval(app.getCookieConfig().getTimeout()); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, encKey); byte[] encSessionKey = cipher.doFinal(id.getBytes("UTF-8")); String base64d = new String(org.bouncycastle.util.encoders.Base64.encode(encSessionKey)); Token token = new Token(); token.setEncryptedRequest(base64d); token.setIv(new String(org.bouncycastle.util.encoders.Base64.encode(cipher.getIV()))); Gson gson = new Gson(); String cookie = gson.toJson(token); byte[] btoken = cookie.getBytes("UTF-8"); String encCookie = new String(org.bouncycastle.util.encoders.Base64.encode(btoken)); Cookie sessionCookie; sessionCookie = new Cookie(app.getCookieConfig().getSessionCookieName(), encCookie); // logger.debug("session size : " + // org.apache.directory.shared.ldap.util.Base64.encode(encSession).length); String domain = ProxyTools.getInstance().getCookieDomain(app.getCookieConfig(), req); if (domain != null) { sessionCookie.setDomain(domain); } sessionCookie.setPath("/"); sessionCookie.setSecure(false); sessionCookie.setMaxAge(-1); sessionCookie.setSecure(app.getCookieConfig().isSecure()); sessionCookie.setHttpOnly(app.getCookieConfig().isHttpOnly() != null && app.getCookieConfig().isHttpOnly()); resp.addCookie(sessionCookie); // delete the opensession if it exists if (cfg.getCfg().getApplications().getOpenSessionCookieName() != null && !cfg.getCfg().getApplications().getOpenSessionCookieName().isEmpty()) { Cookie openSessionCookie = new Cookie(cfg.getCfg().getApplications().getOpenSessionCookieName(), id); openSessionCookie.setPath("/"); openSessionCookie.setSecure(cfg.getCfg().getApplications().isOpenSessionSecure()); openSessionCookie.setHttpOnly(cfg.getCfg().getApplications().isOpenSessionHttpOnly()); openSessionCookie.setMaxAge(0); resp.addCookie(openSessionCookie); } sessions.put(id, tsession); return tsession; }
From source file:eu.europa.esig.dss.cades.signature.CadesLevelBaselineLTATimestampExtractor.java
private void digestAndAddToList(ASN1EncodableVector crlsHashIndex, byte[] encoded) { final byte[] digest = DSSUtils.digest(hashIndexDigestAlgorithm, encoded); if (LOG.isDebugEnabled()) { LOG.debug("Adding to crlsHashIndex with hash {}", Hex.encodeHexString(digest)); }//w w w . j ava2 s.c o m final DEROctetString derOctetStringDigest = new DEROctetString(digest); crlsHashIndex.add(derOctetStringDigest); }