List of usage examples for org.apache.commons.codec.digest DigestUtils sha384Hex
public static String sha384Hex(String data)
From source file:org.sonar.server.usertoken.TokenGeneratorImpl.java
@Override public String hash(String token) { return DigestUtils.sha384Hex(token); }
From source file:org.trancecode.xproc.step.HashStepProcessor.java
@Override protected void execute(final StepInput input, final StepOutput output) { final XdmNode sourceDocument = input.readNode(XProcPorts.SOURCE); final String value = input.getOptionValue(XProcOptions.VALUE); assert value != null; LOG.trace("value = {}", value); final String algorithm = input.getOptionValue(XProcOptions.ALGORITHM); assert algorithm != null; LOG.trace("algorithm = {}", algorithm); final String match = input.getOptionValue(XProcOptions.MATCH); assert match != null; LOG.trace("match = {}", match); final String version = input.getOptionValue(XProcOptions.VERSION); LOG.trace("version = {}", version); final String hashValue; if (StringUtils.equalsIgnoreCase("crc", algorithm)) { if ("32".equals(version) || version == null) { final CRC32 crc32 = new CRC32(); crc32.update(value.getBytes()); hashValue = Long.toHexString(crc32.getValue()); } else {/*from w w w . j a va2s . com*/ throw XProcExceptions.xc0036(input.getLocation()); } } else if (StringUtils.equalsIgnoreCase("md", algorithm)) { if (version == null || "5".equals(version)) { hashValue = DigestUtils.md5Hex(value); } else { throw XProcExceptions.xc0036(input.getLocation()); } } else if (StringUtils.equalsIgnoreCase("sha", algorithm)) { if (version == null || "1".equals(version)) { hashValue = DigestUtils.shaHex(value); } else if ("256".equals(version)) { hashValue = DigestUtils.sha256Hex(value); } else if ("384".equals(version)) { hashValue = DigestUtils.sha384Hex(value); } else if ("512".equals(version)) { hashValue = DigestUtils.sha512Hex(value); } else { throw XProcExceptions.xc0036(input.getLocation()); } } else { throw XProcExceptions.xc0036(input.getLocation()); } final SaxonProcessorDelegate hashDelegate = new AbstractSaxonProcessorDelegate() { @Override public boolean startDocument(final XdmNode node, final SaxonBuilder builder) { return true; } @Override public void endDocument(final XdmNode node, final SaxonBuilder builder) { } @Override public EnumSet<NextSteps> startElement(final XdmNode element, final SaxonBuilder builder) { builder.text(hashValue); return EnumSet.noneOf(NextSteps.class); } @Override public void endElement(final XdmNode node, final SaxonBuilder builder) { builder.endElement(); } @Override public void attribute(final XdmNode node, final SaxonBuilder builder) { builder.attribute(node.getNodeName(), hashValue); } @Override public void comment(final XdmNode node, final SaxonBuilder builder) { builder.comment(hashValue); } @Override public void processingInstruction(final XdmNode node, final SaxonBuilder builder) { builder.processingInstruction(node.getNodeName().getLocalName(), hashValue); } @Override public void text(final XdmNode node, final SaxonBuilder builder) { builder.text(hashValue); } }; final SaxonProcessor hashProcessor = new SaxonProcessor(input.getPipelineContext().getProcessor(), SaxonProcessorDelegates.forXsltMatchPattern(input.getPipelineContext().getProcessor(), match, input.getStep().getNode(), hashDelegate, new CopyingSaxonProcessorDelegate())); final XdmNode result = hashProcessor.apply(sourceDocument); output.writeNodes(XProcPorts.RESULT, result); }
From source file:org.zaproxy.zap.extension.pscanrulesBeta.UsernameIdorScanner.java
@Override public void scanHttpResponseReceive(HttpMessage msg, int id, Source source) { List<User> scanUsers = getUsers(); if (scanUsers.isEmpty()) { // Should continue if not empty if (LOGGER.isDebugEnabled()) { LOGGER.debug("There does not appear to be any contexts with configured users."); }//from w ww . j a v a 2s.com return; } long start = System.currentTimeMillis(); String response = msg.getResponseHeader().toString() + msg.getResponseBody().toString(); String username; for (User user : scanUsers) { username = user.getName(); Map<String, String> hashes = new HashMap<String, String>(); hashes.put("MD2", DigestUtils.md2Hex(username)); hashes.put("MD5", DigestUtils.md5Hex(username)); hashes.put("SHA1", DigestUtils.sha1Hex(username)); hashes.put("SHA256", DigestUtils.sha256Hex(username)); hashes.put("SHA384", DigestUtils.sha384Hex(username)); hashes.put("SHA512", DigestUtils.sha512Hex(username)); for (Map.Entry<String, String> entry : hashes.entrySet()) { String hash = entry.getValue(); String evidence = match(response, Pattern.compile(hash, Pattern.CASE_INSENSITIVE)); if (evidence != null) { this.raiseAlert(username, evidence, entry.getKey(), id, msg); } } } if (LOGGER.isDebugEnabled()) { LOGGER.debug("\tScan of record " + id + " took " + (System.currentTimeMillis() - start) + " ms"); } }
From source file:tk.jomp16.plugin.codecutils.CodecUtils.java
@Command("hash") public void hash(CommandEvent commandEvent) { if (commandEvent.getArgs().size() >= 2) { switch (commandEvent.getArgs().get(0).toLowerCase()) { case "md2": commandEvent.respond(DigestUtils.md2Hex(commandEvent.getArgs().get(1))); break; case "md5": commandEvent.respond(DigestUtils.md5Hex(commandEvent.getArgs().get(1))); break; case "sha1": commandEvent.respond(DigestUtils.sha1Hex(commandEvent.getArgs().get(1))); break; case "sha256": commandEvent.respond(DigestUtils.sha256Hex(commandEvent.getArgs().get(1))); break; case "sha384": commandEvent.respond(DigestUtils.sha384Hex(commandEvent.getArgs().get(1))); break; case "sha512": commandEvent.respond(DigestUtils.sha512Hex(commandEvent.getArgs().get(1))); break; default:/* ww w . j av a2s . c om*/ commandEvent.showUsage(this, "hash"); break; } } else { commandEvent.showUsage(this, "hash"); } }
From source file:yoyo.framework.standard.shared.CodecUtils.java
/** * SHA-384(HEX)?/*from www. j a v a 2s . co m*/ * @param data ? * @return SHA-384(HEX) */ public static String sha384Hex(final String data) { return DigestUtils.sha384Hex(data); }