List of usage examples for org.apache.commons.codec.digest DigestUtils shaHex
@Deprecated public static String shaHex(String data)
From source file:spdxedit.SpdxLogic.java
public static String computePackageVerificationCode(SpdxPackage pkg) { try {/* w w w . jav a 2 s. co m*/ String combinedSha1s = Arrays.stream(pkg.getFiles()) .filter(spdxFile -> !ArrayUtils.contains( getVerificationCodeHandlingException(pkg).getExcludedFileNames(), spdxFile.getName())) // Filter // out // excluded // files .map(SpdxLogic::getSha1Checksum) // Get sha1 checksum for // each file .map(Checksum::getValue) // Get the string value of the // checksum .sorted() // Sort them .collect(Collectors.joining()) // Combine them into a single // string ; assert (!"".equals(combinedSha1s)); String result = DigestUtils.shaHex(combinedSha1s); return result; } catch (InvalidSPDXAnalysisException e) { throw new RuntimeException(e); } }
From source file:test.be.fedict.eid.applet.PcscTest.java
@Test public void pcscAuthnSignature() throws Exception { this.messages = new Messages(Locale.GERMAN); PcscEid pcscEid = new PcscEid(new TestView(), this.messages); if (false == pcscEid.isEidPresent()) { LOG.debug("insert eID card"); pcscEid.waitForEidPresent();// www.ja va2s.c o m } byte[] challenge = "hello world".getBytes(); byte[] signatureValue; List<X509Certificate> authnCertChain; try { // pcscEid.logoff(); // pcscEid.selectBelpicJavaCardApplet(); signatureValue = pcscEid.signAuthn(challenge); long t0 = System.currentTimeMillis(); pcscEid.signAuthn(challenge); long t1 = System.currentTimeMillis(); LOG.debug("dt: " + (t1 - t0)); authnCertChain = pcscEid.getAuthnCertificateChain(); LOG.debug("key size: " + authnCertChain.get(0).getPublicKey().getEncoded().length * 8); // pcscEid.logoff(); } finally { pcscEid.close(); } Signature signature = Signature.getInstance("SHA1withRSA"); signature.initVerify(authnCertChain.get(0).getPublicKey()); signature.update(challenge); boolean result = signature.verify(signatureValue); assertTrue(result); LOG.debug("sha1 hex: " + DigestUtils.shaHex(authnCertChain.get(0).getPublicKey().getEncoded())); }
From source file:test.integ.be.agiv.security.PKCS12Test.java
@Test public void testLoadPKCS12() throws Exception { Config config = new Config(); String pkcs12Path = config.getPKCS12Path(); String pkcs12Password = config.getPKCS12Password(); InputStream pkcs12InputStream = new FileInputStream(pkcs12Path); assertNotNull(pkcs12InputStream); LOG.debug("loading PKCS12 keystore"); KeyStore keyStore = KeyStore.getInstance("PKCS12"); keyStore.load(pkcs12InputStream, pkcs12Password.toCharArray()); Enumeration<String> aliases = keyStore.aliases(); while (aliases.hasMoreElements()) { String alias = aliases.nextElement(); LOG.debug("alias: " + alias); X509Certificate certificate = (X509Certificate) keyStore.getCertificate(alias); LOG.debug("certificate: " + certificate); PrivateKey privateKey = (PrivateKey) keyStore.getKey(alias, pkcs12Password.toCharArray()); LOG.debug("private key algo: " + privateKey.getAlgorithm()); assertEquals("RSA", privateKey.getAlgorithm()); LOG.debug("certificate fingerprint: " + DigestUtils.shaHex(certificate.getEncoded())); }/*w w w .j a v a 2 s . c om*/ }
From source file:test.unit.be.fedict.eid.tsl.FingerprintTest.java
@Test public void testECSSLFingerprint() throws Exception { // setup/* w w w. j a v a2 s . c o m*/ X509Certificate sslCert = TrustTestUtils.loadCertificateFromResource("eu/ec.europa.eu.der"); // operate LOG.debug("EC SSL SHA-1 fingerprint: " + DigestUtils.shaHex(sslCert.getEncoded())); LOG.debug("EC SSL SHA-256 fingerprint: " + DigestUtils.sha256Hex(sslCert.getEncoded())); }
From source file:test.unit.be.fedict.eid.tsl.FingerprintTest.java
@Test public void testECFingerprint() throws Exception { // setup//from w ww. ja va2 s . c o m Document euTSLDocument = TrustTestUtils.loadDocumentFromResource("eu/tl-mp-2.xml"); TrustServiceList euTSL = TrustServiceListFactory.newInstance(euTSLDocument); X509Certificate euCertificate = euTSL.verifySignature(); // operate LOG.debug("EC SHA-1 fingerprint: " + DigestUtils.shaHex(euCertificate.getEncoded())); LOG.debug("EC SHA-256 fingerprint: " + DigestUtils.sha256Hex(euCertificate.getEncoded())); }
From source file:test.unit.be.fedict.eid.tsl.FingerprintTest.java
@Test public void testNewECFingerprint() throws Exception { // setup//from www . java2 s.co m Document euTSLDocument = TrustTestUtils.loadDocumentFromResource("eu/tl-mp-33.xml"); TrustServiceList euTSL = TrustServiceListFactory.newInstance(euTSLDocument); X509Certificate euCertificate = euTSL.verifySignature(); // operate LOG.debug("EC SHA-1 fingerprint: " + DigestUtils.shaHex(euCertificate.getEncoded())); LOG.debug("EC SHA-256 fingerprint: " + DigestUtils.sha256Hex(euCertificate.getEncoded())); }
From source file:ti.modules.titanium.utils.UtilsModule.java
@Kroll.method public String sha1(Object obj) { String data = convertToString(obj); if (data != null) { return DigestUtils.shaHex(data); }/*from w w w. j av a 2s . c om*/ return null; }
From source file:uk.me.viv.logmyride.KMLFile.java
/** * @todo push this down into a MotionX specific KML class * @return// w ww .j ava2s.c o m */ public Map<String, String> getDescription() { String[] descriptionProperties = { "Date", "Distance", "Elapsed Time", "Avg Speed", "Max Speed", "Avg Pace", "Min Altitude", "Max Altitude", "Start Time", "Finish Time", }; Map<String, String> description = new HashMap<>(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder; try { builder = factory.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(this.kml)); try { Document doc = builder.parse(is); XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xpath = xPathfactory.newXPath(); description.put("Name", xpath.evaluate("//Document/name/text()", doc)); for (String property : descriptionProperties) { description.put(property, xpath.evaluate("//td[text()=\"" + property + ":\"]/following::td[1]/text()", doc)); } description.put("Filename", this.getFilename()); description.put("ID", DigestUtils.shaHex(Integer.toString(description.hashCode()))); } catch (SAXException ex) { Logger.getLogger(KMLFile.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(KMLFile.class.getName()).log(Level.SEVERE, null, ex); } catch (XPathExpressionException ex) { Logger.getLogger(KMLFile.class.getName()).log(Level.SEVERE, null, ex); } } catch (ParserConfigurationException ex) { Logger.getLogger(KMLFile.class.getName()).log(Level.SEVERE, null, ex); } return description; }
From source file:util.Digesto.java
public static String gerarDigestoSHA1(String chave) { return DigestUtils.shaHex(chave); }
From source file:util.ModuleChecker.java
public static String sha1(File file) throws IOException { InputStream is = new FileInputStream(file); try {/* w w w . j a va2 s . c o m*/ String realChecksum = DigestUtils.shaHex(is); return realChecksum; } finally { is.close(); } }