Java Code Examples for org.apache.commons.codec.digest.DigestUtils
The following examples show how to use
org.apache.commons.codec.digest.DigestUtils. These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Alice-LiveMan Source File: SeventeenBroadcastService.java License: GNU Affero General Public License v3.0 | 6 votes |
@Override public String getBroadcastCookies(String username, String password, String captcha) throws Exception { Map<String, String> requestHeader = buildRequestHeader(null); String loginJSON = HttpRequestUtil.downloadUrl(new URI(API_17APP_GATEWAY), null, "data={\"openID\":\"" + username + "\",\"password\":\"" + DigestUtils.md5Hex(password) + "\",\"action\":\"loginAction\"}", requestHeader, StandardCharsets.UTF_8); JSONObject loginObj = JSONObject.parseObject(loginJSON).getJSONObject("data"); if ("success".equals(loginObj.get("result"))) { return loginObj.getString("accessToken"); } else { log.error("17Live登录失败" + loginJSON); String message = loginObj.getString("message"); if ("no_such_user".equals(message)) { throw new RuntimeException("用户名或密码错误"); } else { throw new RuntimeException("未知错误[" + message + "]"); } } }
Example 2
Source Project: freehealth-connector Source File: MapperFactory.java License: GNU Affero General Public License v3.0 | 6 votes |
public static Mapper getMapper(String... mappingFiles) { Set<String> mappingSet = new TreeSet(); mappingSet.addAll(Arrays.asList(mappingFiles)); MessageDigest complete = DigestUtils.getMd5Digest(); Iterator i$ = mappingSet.iterator(); while(i$.hasNext()) { String mapping = (String)i$.next(); complete.update(mapping.getBytes()); } String key = new String(Base64.encode(complete.digest())); if (!cache.containsKey(key)) { Map<String, Object> options = new HashMap(); options.put("be.ehealth.technicalconnector.mapper.configfiles", mappingFiles); try { cache.put(key, helper.getImplementation(options)); } catch (TechnicalConnectorException var6) { throw new IllegalArgumentException(var6); } } return (Mapper)cache.get(key); }
Example 3
Source Project: webmagic Source File: JsonFilePageModelPipeline.java License: Apache License 2.0 | 6 votes |
@Override public void process(Object o, Task task) { String path = this.path + PATH_SEPERATOR + task.getUUID() + PATH_SEPERATOR; try { String filename; if (o instanceof HasKey) { filename = path + ((HasKey) o).key() + ".json"; } else { filename = path + DigestUtils.md5Hex(ToStringBuilder.reflectionToString(o)) + ".json"; } PrintWriter printWriter = new PrintWriter(new FileWriter(getFile(filename))); printWriter.write(JSON.toJSONString(o)); printWriter.close(); } catch (IOException e) { logger.warn("write file error", e); } }
Example 4
Source Project: codenjoy Source File: RestController.java License: GNU General Public License v3.0 | 6 votes |
private void regeneratePlayerPassword(Player player) { String generated = generator.password(); // это делает фронтенд, но у нас тут чистый пароль String md5 = DigestUtils.md5Hex(generated); // еще раз захешируем String hashed = passwordEncoder.encode(md5); player.setPassword(hashed); // и подсчитаем code(md5(bcrypt(password))) player.setCode(Hash.getCode(player.getId(), hashed)); players.update(player); sms.sendSmsTo(player.getPhone(), generated, SmsService.SmsType.NEW_PASSWORD); ticket.logInfo(String.format("Updated password '%s' for %s", generated, new ServerLocation(player))); }
Example 5
Source Project: elasticsearch-river-github Source File: GitHubRiver.java License: Apache License 2.0 | 6 votes |
private IndexRequest indexOther(JsonElement e, String type, boolean overwrite) { JsonObject obj = e.getAsJsonObject(); // handle objects that don't have IDs (i.e. labels) // set the ID to the MD5 hash of the string representation String id; if (obj.has("id")) { id = obj.get("id").getAsString(); } else { id = DigestUtils.md5Hex(e.toString()); } IndexRequest req = new IndexRequest(index) .type(type) .id(id).create(!overwrite) .source(e.toString()); return req; }
Example 6
Source Project: cognition Source File: LineRegexReplaceInRegionBolt.java License: Apache License 2.0 | 6 votes |
@Override protected void execute(Tuple tuple, RecordCollector collector) { byte[] bytes = (byte[]) tuple.getValue(0); String record = new String(bytes); String sha1Checksum = DigestUtils.shaHex(bytes); if (StringUtils.isBlank(record)) { // skips blank entries logger.info("received blank record"); return; } LogRecord logRecord = new LogRecord(sha1Checksum); logRecord.addMetadataValue(SHA1_CHECKSUM, sha1Checksum); String recordAfterReplace = replaceAll(record); populateLogRecord(logRecord, recordAfterReplace); collector.emit(logRecord); }
Example 7
Source Project: eladmin Source File: RedisConfig.java License: Apache License 2.0 | 6 votes |
/** * 自定义缓存key生成策略,默认将使用该策略 */ @Bean @Override public KeyGenerator keyGenerator() { return (target, method, params) -> { Map<String,Object> container = new HashMap<>(3); Class<?> targetClassClass = target.getClass(); // 类地址 container.put("class",targetClassClass.toGenericString()); // 方法名称 container.put("methodName",method.getName()); // 包名称 container.put("package",targetClassClass.getPackage()); // 参数列表 for (int i = 0; i < params.length; i++) { container.put(String.valueOf(i),params[i]); } // 转为JSON字符串 String jsonString = JSON.toJSONString(container); // 做SHA256 Hash计算,得到一个SHA256摘要作为Key return DigestUtils.sha256Hex(jsonString); }; }
Example 8
Source Project: rapidminer-studio Source File: ConnectionInformationFileUtils.java License: GNU Affero General Public License v3.0 | 6 votes |
/** * Copies the given files to the specified {@code root/dirName} and creates {@code .md5} hash files for each. */ static void copyFilesToZip(Path root, List<Path> filesToCopy, String dirName) throws IOException { if (filesToCopy == null || filesToCopy.isEmpty() || dirName == null) { return; } Path path = root.resolve(dirName); Files.createDirectory(path); MessageDigest md5 = DigestUtils.getMd5Digest(); for (Path fileToCopy : filesToCopy) { Path fileName = fileToCopy.getFileName(); Path nestedFilePath = path.resolve(fileName.toString()); try (InputStream is = Files.newInputStream(fileToCopy); DigestInputStream dis = new DigestInputStream(is, md5); BufferedWriter md5Writer = Files.newBufferedWriter(path.resolve(fileName + ConnectionInformationSerializer.MD5_SUFFIX))) { Files.copy(dis, nestedFilePath); md5Writer.write(Hex.encodeHexString(md5.digest())); } } }
Example 9
Source Project: unidbg Source File: IpaLoader.java License: Apache License 2.0 | 6 votes |
protected String[] getEnvs(File rootDir) throws IOException { List<String> list = new ArrayList<>(); list.add("PrintExceptionThrow=YES"); // log backtrace of every objc_exception_throw() if (log.isDebugEnabled()) { list.add("OBJC_HELP=YES"); // describe available environment variables // list.add("OBJC_PRINT_OPTIONS=YES"); // list which options are set // list.add("OBJC_PRINT_INITIALIZE_METHODS=YES"); // log calls to class +initialize methods list.add("OBJC_PRINT_CLASS_SETUP=YES"); // log progress of class and category setup list.add("OBJC_PRINT_PROTOCOL_SETUP=YES"); // log progress of protocol setup list.add("OBJC_PRINT_IVAR_SETUP=YES"); // log processing of non-fragile ivars list.add("OBJC_PRINT_VTABLE_SETUP=YES"); // log processing of class vtables } UUID uuid = UUID.nameUUIDFromBytes(DigestUtils.md5(appDir + "_Documents")); String homeDir = "/var/mobile/Containers/Data/Application/" + uuid.toString().toUpperCase(); list.add("CFFIXED_USER_HOME=" + homeDir); FileUtils.forceMkdir(new File(rootDir, homeDir)); return list.toArray(new String[0]); }
Example 10
Source Project: freehealth-connector Source File: MapperFactory.java License: GNU Affero General Public License v3.0 | 6 votes |
public static Mapper getMapper(String... mappingFiles) { Set<String> mappingSet = new TreeSet(); mappingSet.addAll(Arrays.asList(mappingFiles)); MessageDigest complete = DigestUtils.getMd5Digest(); Iterator i$ = mappingSet.iterator(); while(i$.hasNext()) { String mapping = (String)i$.next(); complete.update(mapping.getBytes()); } String key = new String(Base64.encode(complete.digest())); if (!cache.containsKey(key)) { Map<String, Object> options = new HashMap(); options.put("be.ehealth.technicalconnector.mapper.configfiles", mappingFiles); try { cache.put(key, helper.getImplementation(options)); } catch (TechnicalConnectorException var6) { throw new IllegalArgumentException(var6); } } return (Mapper)cache.get(key); }
Example 11
Source Project: beam Source File: BeamSalUhfSpecialTypeAndValueTest.java License: Apache License 2.0 | 6 votes |
@Test public void testSHA512() throws Exception { Schema resultType = Schema.builder().addByteArrayField("field").build(); Row resultRow1 = Row.withSchema(resultType).addValues(DigestUtils.sha512("foobar".getBytes(UTF_8))).build(); Row resultRow2 = Row.withSchema(resultType).addValues(DigestUtils.sha512(" ".getBytes(UTF_8))).build(); Row resultRow3 = Row.withSchema(resultType) .addValues(DigestUtils.sha512("abcABCжщфЖЩФ".getBytes(UTF_8))) .build(); String sql = "SELECT SHA512(f_bytes) FROM PCOLLECTION WHERE f_func = 'HashingFn'"; PCollection<Row> result = boundedInputBytes.apply("testUdf", SqlTransform.query(sql)); PAssert.that(result).containsInAnyOrder(resultRow1, resultRow2, resultRow3); pipeline.run().waitUntilFinish(); }
Example 12
Source Project: markup-document-builder Source File: AbstractMarkupDocBuilder.java License: Apache License 2.0 | 6 votes |
protected String normalizeAnchor(Markup spaceEscape, String anchor) { String normalizedAnchor = defaultString(anchorPrefix) + anchor.trim(); normalizedAnchor = Normalizer.normalize(normalizedAnchor, Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", ""); normalizedAnchor = ANCHOR_IGNORABLE_PATTERN.matcher(normalizedAnchor).replaceAll(spaceEscape.toString()); normalizedAnchor = normalizedAnchor.replaceAll(String.format("([%1$s])([%1$s]+)", ANCHOR_SEPARATION_CHARACTERS), "$1"); normalizedAnchor = StringUtils.strip(normalizedAnchor, ANCHOR_SEPARATION_CHARACTERS); normalizedAnchor = normalizedAnchor.trim().toLowerCase(); String validAnchor = ANCHOR_UNIGNORABLE_PATTERN.matcher(normalizedAnchor).replaceAll(""); if (validAnchor.length() != normalizedAnchor.length()) normalizedAnchor = DigestUtils.md5Hex(normalizedAnchor); else normalizedAnchor = validAnchor; return normalizedAnchor; }
Example 13
Source Project: icure-backend Source File: DocumentDAOImpl.java License: GNU General Public License v2.0 | 6 votes |
@Override protected void beforeSave(Document entity) { super.beforeSave(entity); if (entity.getAttachment() != null) { String newAttachmentId = DigestUtils.sha256Hex(entity.getAttachment()); if (!newAttachmentId.equals(entity.getAttachmentId())) { if (entity.getAttachments().containsKey(entity.getAttachmentId())) { entity.setRev(deleteAttachment(entity.getId(), entity.getRev(), entity.getAttachmentId())); entity.getAttachments().remove(entity.getAttachmentId()); } entity.setAttachmentId(newAttachmentId); entity.setAttachmentDirty(true); } } else { if (entity.getAttachmentId() != null) { entity.setRev(deleteAttachment(entity.getId(), entity.getRev(), entity.getAttachmentId())); entity.setAttachmentId(null); entity.setAttachmentDirty(false); } } }
Example 14
Source Project: gocd Source File: AgentRegistrationControllerTest.java License: Apache License 2.0 | 6 votes |
@Test public void checkAgentStatusShouldIncludeMd5Checksum_forAgent_forLauncher_whenChecksumsAreCached() throws Exception { when(pluginsZip.md5()).thenReturn("plugins-zip-md5"); when(systemEnvironment.get(AGENT_EXTRA_PROPERTIES)).thenReturn("extra=property"); controller.checkAgentStatus(response); try (InputStream stream = JarDetector.tfsJar(systemEnvironment).getJarURL().openStream()) { assertEquals(DigestUtils.md5Hex(stream), response.getHeader(SystemEnvironment.AGENT_TFS_SDK_MD5_HEADER)); } try (InputStream stream = JarDetector.create(systemEnvironment, "agent-launcher.jar").invoke()) { assertEquals(DigestUtils.md5Hex(stream), response.getHeader(SystemEnvironment.AGENT_LAUNCHER_CONTENT_MD5_HEADER)); } try (InputStream stream = JarDetector.create(systemEnvironment, "agent.jar").invoke()) { assertEquals(DigestUtils.md5Hex(stream), response.getHeader(SystemEnvironment.AGENT_CONTENT_MD5_HEADER)); } assertEquals("plugins-zip-md5", response.getHeader(SystemEnvironment.AGENT_PLUGINS_ZIP_MD5_HEADER)); }
Example 15
Source Project: mojito Source File: AssetService.java License: Apache License 2.0 | 6 votes |
/** * Indicates if an asset needs to be updated. * <p> * First compare the asset content with the new content and the options used for the extraction. If the contents are * the same check that the last successful extraction correspond to the * latest version of the asset. If not it means an issue happen before and * that regardless of the content being the same, the asset needs to updated * and reprocessed. * * @param assetContent The asset to be compared * @param newAssetContent The content to be compared * @param optionsMd5 * @return true if the content of the asset is different from the new * content, false otherwise */ private boolean isAssetProcessingNeeded(AssetExtractionByBranch assetExtractionByBranch, String newAssetContent, List<String> newFilterOptions) { boolean assetProcessingNeeded = false; if (assetExtractionByBranch == null) { logger.debug("No active asset extraction, processing needed"); assetProcessingNeeded = true; } else if (assetExtractionByBranch.getDeleted()) { logger.debug("Asset extraction deleted, processing needed"); assetProcessingNeeded = true; } else if (!DigestUtils.md5Hex(newAssetContent).equals(assetExtractionByBranch.getAssetExtraction().getContentMd5())) { logger.debug("Content has changed, processing needed"); assetProcessingNeeded = true; } else if (!filterOptionsMd5Builder.md5(newFilterOptions).equals(assetExtractionByBranch.getAssetExtraction().getFilterOptionsMd5())) { logger.debug("filter options have changed, processing needed"); assetProcessingNeeded = true; } else { logger.debug("Asset processing not needed"); } return assetProcessingNeeded; }
Example 16
Source Project: o2oa Source File: SyncOrganization.java License: GNU Affero General Public License v3.0 | 6 votes |
private Unit checkUnit(Business business, PullResult result, Unit sup, Department org) throws Exception { Unit unit = business.unit().getWithQiyeweixinIdObject(Objects.toString(org.getId())); if (null != unit) { if ((null == sup) && (StringUtils.isNotEmpty(unit.getSuperior()))) { /* 不是一个顶层组织所以只能删除重建 */ removeUnit(business, result, unit); unit = null; } if ((null != sup) && (!StringUtils.equals(sup.getId(), unit.getSuperior()))) { /* 指定的上级部门和预期不符 */ removeUnit(business, result, unit); unit = null; } } if (null == unit) { unit = this.createUnit(business, result, sup, org); } else { if (!StringUtils.equals(unit.getQiyeweixinHash(), DigestUtils.sha256Hex(XGsonBuilder.toJson(org)))) { logger.print("组织【{}】的hash值变化,更新组织====",org.getName()); unit = this.updateUnit(business, result, unit, org); } } return unit; }
Example 17
Source Project: lucene-solr Source File: PackageStoreAPI.java License: Apache License 2.0 | 6 votes |
private void validate(List<String> sigs, ByteBuffer buf) throws SolrException, IOException { Map<String, byte[]> keys = packageStore.getKeys(); if (keys == null || keys.isEmpty()) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "package store does not have any keys"); } CryptoKeys cryptoKeys = null; try { cryptoKeys = new CryptoKeys(keys); } catch (Exception e) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error parsing public keys in Package store"); } for (String sig : sigs) { if (cryptoKeys.verify(sig, buf) == null) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Signature does not match any public key : " + sig +" len: "+buf.limit()+ " content sha512: "+ DigestUtils.sha512Hex(new ByteBufferInputStream(buf))); } } }
Example 18
Source Project: text_converter Source File: Sha384Hash.java License: GNU General Public License v3.0 | 5 votes |
@Override public String encode(String text) { try { return DigestUtils.sha384Hex(text.getBytes()); } catch (Exception e) { return ""; } }
Example 19
Source Project: beam Source File: BeamSqlUdfExpressionTest.java License: Apache License 2.0 | 5 votes |
@Test public void testSHA256() throws Exception { ExpressionChecker checker = new ExpressionChecker() .addExpr("SHA256('foobar')", DigestUtils.sha256("foobar")) .addExpr("SHA256('中文')", DigestUtils.sha256("中文")) .addExprWithNullExpectedValue("SHA256(CAST(NULL AS VARCHAR(0)))", TypeName.BYTES); checker.buildRunAndCheck(); }
Example 20
Source Project: floobits-intellij Source File: Colors.java License: Apache License 2.0 | 5 votes |
public static JBColor getColorForUser(String username) { String color = color_map.get(username); if (color != null) { int indexOf = HIGHLIGHT_COLORS.indexOf(color); if (indexOf >= 0) { return colors[indexOf]; } } int i = 0; for(char c : DigestUtils.md5Hex(username).toCharArray()) { i += (int)c; } return colors[i % colors.length]; }
Example 21
Source Project: commafeed Source File: FeedUpdateService.java License: Apache License 2.0 | 5 votes |
/** * this is NOT thread-safe */ public boolean addEntry(Feed feed, FeedEntry entry, List<FeedSubscription> subscriptions) { Long existing = feedEntryDAO.findExisting(entry.getGuid(), feed); if (existing != null) { return false; } FeedEntryContent content = feedEntryContentService.findOrCreate(entry.getContent(), feed.getLink()); entry.setGuidHash(DigestUtils.sha1Hex(entry.getGuid())); entry.setContent(content); entry.setInserted(new Date()); entry.setFeed(feed); feedEntryDAO.saveOrUpdate(entry); // if filter does not match the entry, mark it as read for (FeedSubscription sub : subscriptions) { boolean matches = true; try { matches = feedEntryFilteringService.filterMatchesEntry(sub.getFilter(), entry); } catch (FeedEntryFilterException e) { log.error("could not evaluate filter {}", sub.getFilter(), e); } if (!matches) { FeedEntryStatus status = new FeedEntryStatus(sub.getUser(), sub, entry); status.setRead(true); feedEntryStatusDAO.saveOrUpdate(status); } } return true; }
Example 22
Source Project: nifi Source File: PutGridFSIT.java License: Apache License 2.0 | 5 votes |
private void testHashUniqueness(AllowableValue value) { String hashAttr = "hash.value"; String fileName = "test_duplicates.txt"; String content = "Hello, world"; String hash = DigestUtils.md5Hex(content); Map<String, String> attrs = new HashMap<>(); attrs.put(CoreAttributes.FILENAME.key(), fileName); attrs.put(hashAttr, hash); testUniqueness(attrs, content, value); }
Example 23
Source Project: hadoop-ozone Source File: ContinueToken.java License: Apache License 2.0 | 5 votes |
private static void checkHash(String key, String hex, String digest) throws OS3Exception { String digestActualKey = DigestUtils.sha256Hex(hex); if (!digest.equals(digestActualKey)) { OS3Exception ex = S3ErrorTable.newError(S3ErrorTable .INVALID_ARGUMENT, key); ex.setErrorMessage("The continuation token provided is incorrect"); throw ex; } }
Example 24
Source Project: TomboloDigitalConnector Source File: JournalEntryUtilsTest.java License: MIT License | 5 votes |
@Test public void getJournalEntryForDatasourceIdGeoNull() throws Exception { DatabaseJournalEntry entry = JournalEntryUtils.getJournalEntryForDatasourceId( "class.name", "datasource-id", Arrays.asList("geo"), null, null); assertEquals("class.name", entry.getClassName()); assertEquals("datasource-id:"+ DigestUtils.md5Hex("geo||"), entry.getKey()); }
Example 25
Source Project: SPADE Source File: CDM.java License: GNU General Public License v3.0 | 5 votes |
private UUID getUUID(String str){ if(str != null){ byte[] hash = DigestUtils.md5(str); if(hexUUIDs){ hash = String.valueOf(Hex.encodeHex(hash, true)).getBytes(); } return new UUID(hash); } return null; }
Example 26
Source Project: windup Source File: Sha1HexMethod.java License: Eclipse Public License 1.0 | 5 votes |
@Override public String exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException { if (arguments.size() != 1) { throw new TemplateModelException( "Error, method expects one argument (FileModel)"); } StringModel stringModel = (StringModel) arguments.get(0); FileModel fileModel = (FileModel) stringModel.getWrappedObject(); return !fileModel.isDirectory() ? fileModel.getSHA1Hash() : DigestUtils.sha1Hex(fileModel.getFileName()); }
Example 27
Source Project: text_converter Source File: Sha512Hash.java License: GNU General Public License v3.0 | 5 votes |
@NonNull @Override public String encode(@NonNull String text) { try { return DigestUtils.sha512Hex(text.getBytes()); } catch (Exception e) { return ""; } }
Example 28
Source Project: artifact-listener Source File: EmailAddress.java License: Apache License 2.0 | 5 votes |
public EmailAddress copyForUser(User user) { EmailAddress target = new EmailAddress(); target.setEmail(email); target.setStatus(status); target.setUser(user); StringBuilder sb = new StringBuilder(); sb.append(RandomStringUtils.randomAscii(8)) .append(user.getId()) .append(email) .append(user.getCreationDate()); target.setEmailHash(DigestUtils.sha1Hex(sb.toString())); return target; }
Example 29
Source Project: sakai Source File: SakaiReport.java License: Educational Community License v2.0 | 5 votes |
protected boolean validateHash(String sessionid, String query, String hash) { // TODO add in shared secret to make this safer String calculatedHash = DigestUtils.sha256Hex(sessionid + query); log.info("received hash of: " + hash + " calculated hash value as: " + calculatedHash); return hash.equals(calculatedHash); }
Example 30
Source Project: datacollector Source File: TestDisconnectedSecurityInfo.java License: Apache License 2.0 | 5 votes |
@Test public void testInfoPopulation() { DisconnectedSecurityInfo info = new DisconnectedSecurityInfo(); info.addEntry("user", "ph", ImmutableList.of("r"), ImmutableList.of("g")); String userSha = DigestUtils.sha256Hex("user"); DisconnectedSecurityInfo.Entry entry = info.getEntry("user"); Assert.assertEquals(userSha, entry.getUserNameSha()); Assert.assertEquals("ph", entry.getPasswordHash()); Assert.assertEquals(ImmutableList.of("r"), entry.getRoles()); }