當前位置: 首頁>>代碼示例>>Java>>正文


Java DigestUtils.md5Hex方法代碼示例

本文整理匯總了Java中org.apache.commons.codec.digest.DigestUtils.md5Hex方法的典型用法代碼示例。如果您正苦於以下問題:Java DigestUtils.md5Hex方法的具體用法?Java DigestUtils.md5Hex怎麽用?Java DigestUtils.md5Hex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.codec.digest.DigestUtils的用法示例。


在下文中一共展示了DigestUtils.md5Hex方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getAbstract

import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
/** 
 * 生成文件摘要
 * @param strFilePath 文件路徑
 * @param file_digest_type 摘要算法
 * @return 文件摘要結果
 */
public static String getAbstract(String strFilePath, String file_digest_type) throws IOException {
    PartSource file = new FilePartSource(new File(strFilePath));
	if(file_digest_type.equals("MD5")){
		return DigestUtils.md5Hex(file.createInputStream());
	}
	else if(file_digest_type.equals("SHA")) {
		return DigestUtils.sha256Hex(file.createInputStream());
	}
	else {
		return "";
	}
}
 
開發者ID:superkoh,項目名稱:k-framework,代碼行數:19,代碼來源:AlipayCore.java

示例2: test02

import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
@Test
public void test02() throws Exception {
    HttpUrl parse = HttpUrl.parse("http://www.dapenti.com/blog/more.asp?name=xilei&id=123093");
    System.out.println(parse);
    System.out.println(parse.host());

    System.out.println(parse.uri());
    System.out.println(parse.encodedPath());
    System.out.println(parse.encodedQuery());
    System.out.println(parse.query());


    String s = DigestUtils.md5Hex(parse.toString());
    String s2 = DigestUtils.md5Hex(parse.toString());
    System.out.println(s);
    System.out.println(s2);
}
 
開發者ID:jt120,項目名稱:take,代碼行數:18,代碼來源:TakeTest.java

示例3: getInventoryManifest

import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
/**
 * Check if the MD5s of manifest.json and manifest.checksum equal
 * if so, pull out the manifest file and map it into a POJO
 * @return inventoryManifestStorage InventoryManifest, which stores all the elements of the manifest.json file
 */
public InventoryManifest getInventoryManifest() throws Exception {
    // Get manifest.json and transfer it to String
    GetObjectRequest requestJson = new GetObjectRequest(bucketName, bucketKeyJson);
    S3Object jsonObject = s3Client.getObject(requestJson);
    String jsonFile = inputStreamToString(jsonObject.getObjectContent());
    jsonObject.close();

    // Get manifest.checksum and transfer it to String with no whitespace
    GetObjectRequest requestChecksum = new GetObjectRequest(bucketName, bucketKeyChecksum);
    S3Object checksumObject = s3Client.getObject(requestChecksum);
    String expectedChecksum = inputStreamToString(checksumObject.getObjectContent())
            .replaceAll("\\s","");
    checksumObject.close();

    // Compare manifest.json and manifest.checksum's MD5 value
    String actualChecksum = DigestUtils.md5Hex(jsonFile);
    if (!actualChecksum.equals(expectedChecksum)) {
        throw new ChecksumMismatchException (expectedChecksum, actualChecksum);
    }

    return mapper.readValue(jsonFile, InventoryManifest.class);
}
 
開發者ID:awslabs,項目名稱:s3-inventory-usage-examples,代碼行數:28,代碼來源:InventoryManifestRetriever.java

示例4: push

import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
@Override
public void push(Request request, ISpider spider) {
       Jedis jedis = pool.getResource();
       if (Const.HttpMethod.POST == request.getMethod()
			|| !isDuplicate(request, spider)) {
		log.debug("push to queue {}", request.getUrl());
		 try {
	            jedis.rpush(getQueueKey(spider), request.getUrl());
	            String field = DigestUtils.md5Hex(request.getUrl());
	            byte[] data=SerializationUtils.serialize(request);
	            jedis.hset((ITEM_PREFIX + spider.getName()).getBytes(), field.getBytes(), data);
			} finally {
	            jedis.close();
	        }
	}
   }
 
開發者ID:xbynet,項目名稱:crawler,代碼行數:17,代碼來源:RedisScheduler.java

示例5: getAbstract

import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
/**
 * 生成文件摘要
 *
 * @param strFilePath      文件路徑
 * @param file_digest_type 摘要算法
 * @return 文件摘要結果
 */
public static String getAbstract(String strFilePath, String file_digest_type) throws IOException {
	PartSource file = new FilePartSource(new File(strFilePath));
	if (file_digest_type.equals("MD5")) {
		return DigestUtils.md5Hex(file.createInputStream());
	} else if (file_digest_type.equals("SHA")) {
		return DigestUtils.sha256Hex(file.createInputStream());
	} else {
		return "";
	}
}
 
開發者ID:funtl,項目名稱:framework,代碼行數:18,代碼來源:AlipayCore.java

示例6: getPushUrl

import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
/**
 * 獲取推流地址 如果不傳key和過期時間,將返回不含防盜鏈的url
 */
public static String getPushUrl(StreamUrlConfig config) {
	String liveCode = getStreamId(config.getBizId(), config.getRoomId(), config.getUserId(), config.getDataType());
	if(isNotBlank(config.getKey()) && config.getExpireTime() != null){
		String txTime = Long.toHexString(config.getExpireTime().getTime()/1000).toUpperCase();
		String input = new StringBuilder().append(config.getKey()).append(liveCode)
				.append(txTime).toString();
		try {
			String txSecret = DigestUtils.md5Hex(input.getBytes("UTF-8"));
			return "rtmp://"+config.getBizId()+".livepush.myqcloud.com/live/"+liveCode+"?bizid="+config.getBizId()+"&txSecret="+txSecret+"&txTime="+txTime;
		} catch (Exception e) {
			Throwables.propagate(e);
		}
	}
	return "rtmp://"+config.getBizId()+".livepush.myqcloud.com/live/"+liveCode;
}
 
開發者ID:51wakeup,項目名稱:wakeup-qcloud-sdk,代碼行數:19,代碼來源:QCloudStreamUrlUtil.java

示例7: testPathTooLong

import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
@Test
public void testPathTooLong() {
    final String temp = StringUtils.removeEnd(System.getProperty("java.io.tmpdir"), File.separator);
    final String testPathDirectory = "/Lorem/ipsum/dolor/sit/amet/consetetur/sadipscing/elitr/sed/diam/nonumy/eirmod/tempor/invidunt/ut/labore/et/dolore/magna/aliquyam/erat/sed/diam/voluptua/At/vero/eos/et/accusam/et/justo/duo/dolores/et/ea/rebum/Stet/clita/kasd/gubergren/no/sea";
    final String testPathFile = "takimata.sanc";
    final String testPath = String.format("%s/%s", testPathDirectory, testPathFile);
    final String testPathMD5 = DigestUtils.md5Hex(testPathDirectory);

    final Path file = new Path(testPath, EnumSet.of(Path.Type.file));
    file.attributes().setVersionId("2");
    final Local local = new DefaultTemporaryFileService().create("UID", file);
    final String localFile = local.getAbsolute();
    assertNotEquals(String.format("%s/%s%s/2/%s", temp, "UID", testPathDirectory, testPathFile).replace('/', File.separatorChar), localFile);
    assertEquals(String.format("%s/%s/%s/2/%s", temp, "UID", testPathMD5, testPathFile).replace('/', File.separatorChar), localFile);
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:16,代碼來源:DefaultTemporaryFileServiceTest.java

示例8: getSign

import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
private static String getSign(Map<String, String> params, String appKey, String appSecret) throws UnsupportedEncodingException {
    TreeMap<String, String> paramsSorted = new TreeMap<>(params);
    String data = "";
    paramsSorted.put("appkey", appKey);
    for (String key : paramsSorted.keySet()) {
        if (data != "")
            data += "&";
        data += key + "=" + urlEncode(paramsSorted.get(key));
    }
    if (appSecret == null)
        return data;
    return data + "&sign=" + DigestUtils.md5Hex(data + appSecret);
}
 
開發者ID:Rsplwe,項目名稱:BilibiliAccessKey,代碼行數:14,代碼來源:BilibiliAccessKey.java

示例9: verify

import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
/**
 * 簽名字符串
 *
 * @param text          需要簽名的字符串
 * @param sign          簽名結果
 * @param key           密鑰
 * @param input_charset 編碼格式
 * @return 簽名結果
 */
public static boolean verify(String text, String sign, String key, String input_charset) {
	text = text + key;
	String mysign = DigestUtils.md5Hex(getContentBytes(text, input_charset));
	if (mysign.equals(sign)) {
		return true;
	} else {
		return false;
	}
}
 
開發者ID:funtl,項目名稱:framework,代碼行數:19,代碼來源:MD5.java

示例10: createNonce

import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
/**
 * Create nonce string.
 *
 * @return the nonce
 */
public static String createNonce() {
    final String fmtDate = ZonedDateTime.now().toString();
    final SecureRandom rand = new SecureRandom();
    final Integer randomInt = rand.nextInt();
    return DigestUtils.md5Hex(fmtDate + randomInt);
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:12,代碼來源:DigestAuthenticationUtils.java

示例11: uploadContents

import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
public String uploadContents(String contents) throws Exception {
	if (!rootJson.has("appkey") || !rootJson.has("timestamp")) {
		throw new Exception("appkey, timestamp and validation_token needs to be set.");
	}
	// Construct the json string
	JSONObject uploadJson = new JSONObject();
	uploadJson.put("appkey", rootJson.getString("appkey"));
	uploadJson.put("timestamp", rootJson.getString("timestamp"));
	uploadJson.put("content", contents);
	// Construct the request
	String url = host + uploadPath;
	String postBody = uploadJson.toString();
	String sign = DigestUtils.md5Hex("POST" + url + postBody + appMasterSecret);
	url = url + "?sign=" + sign;
	HttpPost post = new HttpPost(url);
	post.setHeader("User-Agent", USER_AGENT);
	StringEntity se = new StringEntity(postBody, "UTF-8");
	post.setEntity(se);
	// Send the post request and get the response
	HttpResponse response = client.execute(post);
	System.out.println("Response Code : " + response.getStatusLine().getStatusCode());
	BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
	StringBuffer result = new StringBuffer();
	String line = "";
	while ((line = rd.readLine()) != null) {
		result.append(line);
	}
	System.out.println(result.toString());
	// Decode response string and get file_id from it
	JSONObject respJson = new JSONObject(result.toString());
	String ret = respJson.getString("ret");
	if (!ret.equals("SUCCESS")) {
		throw new Exception("Failed to upload file");
	}
	JSONObject data = respJson.getJSONObject("data");
	String fileId = data.getString("file_id");
	// Set file_id into rootJson using setPredefinedKeyValue
	setPredefinedKeyValue("file_id", fileId);
	return fileId;
}
 
開發者ID:marlonwang,項目名稱:raven,代碼行數:41,代碼來源:IOSFilecast.java

示例12: verify

import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
/**
 * 簽名字符串
 * @param text 需要簽名的字符串
 * @param sign 簽名結果
 * @param key 密鑰
 * @param input_charset 編碼格式
 * @return 簽名結果
 */
public static boolean verify(String text, String sign, String key, String input_charset) {
	text = text + key;
	String mysign = DigestUtils.md5Hex(getContentBytes(text, input_charset));
	if(mysign.equals(sign)) {
		return true;
	}
	else {
		return false;
	}
}
 
開發者ID:liuxuanhai,項目名稱:WeiXing_xmu-2016-MrCode,代碼行數:19,代碼來源:MD5.java

示例13: getColorIndex

import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
private static Long getColorIndex(String email) throws NoSuchAlgorithmException {
	String hex = DigestUtils.md5Hex(email);
	return Long.parseLong(hex.substring(0, 15), 16) % COLORS.length;
}
 
開發者ID:jmfgdev,項目名稱:gitplex-mit,代碼行數:5,代碼來源:AvatarGenerator.java

示例14: getItemFromProduct

import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
public LuckyDrawItem getItemFromProduct(Integer rank, Integer level, Boolean isTH) {
	Integer hash = 0, count = 0, price = 0;
	String desc = "", icon = "", vItem = "", vItemType = "";
	Boolean isSold = false;
	
	List<ProductEntity> getProductItems = null;
	
	Integer randomCategory = getRandomCat(rank, isTH, new Random().nextInt(10));
	if(randomCategory == 1) { // Powerup
		getProductItems = productDao.findForEndRace("STORE_POWERUPS", "POWERUP", level);
	} else if(randomCategory == 2) { // Perf
		getProductItems = productDao.findForEndRace("NFSW_NA_EP_PERFORMANCEPARTS", "PERFORMANCEPART", level);
	} else if(randomCategory == 3) { // Skill
		getProductItems = productDao.findForEndRace("NFSW_NA_EP_SKILLMODPARTS", "SKILLMODPART", level);
	} else if(randomCategory == 4) { // Visual
		getProductItems = productDao.findForEndRace(getVisualCatgeory(new Random().nextInt(8)), "VISUALPART", level);
	}
	
	if(getProductItems != null) { // Other part
		Integer randomDrop = new Random().nextInt(getProductItems.size());
		ProductEntity productEntity = getProductItems.get(randomDrop);
		
		if(randomCategory == 1) {
			String strCut = productEntity.getProductTitle().replace("x15", "");
			count = new Random().nextInt(15) + 1;
			desc = strCut + " x" + count;
		} else {
			desc = productEntity.getProductTitle();
			count = 1;
		}
		hash = productEntity.getHash().intValue();
		icon = productEntity.getIcon();
		price = (int)(productEntity.getPrice() / 3.5);
		vItem = DigestUtils.md5Hex(productEntity.getHash().toString());
		vItemType = productEntity.getProductType();
	} else { // Cash part
		Integer cashBonus = new Random().nextInt(25000) + 1;
		desc = String.valueOf(cashBonus) + " CASH";
		icon = "128_cash";
		vItemType = "CASH";
	}
	
	LuckyDrawItem luckyDrawItem = new LuckyDrawItem();
	luckyDrawItem.setDescription(desc);
	luckyDrawItem.setHash(hash);
	luckyDrawItem.setIcon(icon);
	luckyDrawItem.setRemainingUseCount(count);
	luckyDrawItem.setResellPrice(price);
	luckyDrawItem.setVirtualItem(vItem);
	luckyDrawItem.setVirtualItemType(vItemType);
	luckyDrawItem.setWasSold(isSold);
	return luckyDrawItem;
}
 
開發者ID:SoapboxRaceWorld,項目名稱:soapbox-race-core,代碼行數:54,代碼來源:AccoladesFunc.java

示例15: doExecute

import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
@Override
public ActionResult doExecute(HttpServletRequest request, RenderContext renderContext, Resource resource,
                              JCRSessionWrapper session, Map<String, List<String>> parameters,
                              URLResolver urlResolver) throws Exception {

    JSONObject filteredContentMap = new JSONObject();
    final HttpServletResponse response = renderContext.getResponse();

    try {
        View view = null;
        if ( resource.getNode() != null && resource.getNode().getPrimaryNodeType() != null &&
                StringUtils.startsWithAny(resource.getNode().getPrimaryNodeType().getName(),
                        LIST_TEMPLATE_OPTION_TYPES) ){
            view = JahiaUtils.resolveTemplateResourceView(request, resource, renderContext);
            // Set view in the request since the view is needed by the contentModelFactoryService service
            request.setAttribute(JAHIA_SCRIPT_VIEW, view);
        }
        if (view != null) {
            TemplateContentModel templateContentModel = (TemplateContentModel)
                    contentModelFactoryService.getContentModel(request, response, renderContext, resource);

            boolean clientAccessible =
                    (Boolean) templateContentModel.get(CONFIG_PROPERTIES_KEY + DOT + XK_CLIENT_ACCESSIBLE_CP);

            if (clientAccessible) {
                // get list of contexts
                Configuration configuration = configurationProvider.getFor(view);

                Collection<String> props = configuration.asStrings(XK_CLIENT_MODEL_PROPERTIES_CP, Mode.MERGE);
                String[] contexts = props.toArray(new String[0]);

                // get content model json with the XK_CLIENT_MODEL_PROPERTIES_CP contexts
                filteredContentMap = templateContentModel.toJSONObject(contexts);

                // add component id
                String componentContentId = DigestUtils.md5Hex(resource.getPath());
                filteredContentMap.put(XK_CONTENT_ID_CP, componentContentId);
            }

            // add component list with clientaccessible as true on the resource page
            filteredContentMap.put(PAGE_COMPONENT_RESOURCE_LIST_AN, getComponentList(
                    resource, request, response, renderContext));
        }
    } catch (Exception ew) {

        throw new ServletException(ew);
    }

    response.setContentType(SERVER_RESPONSE_CONTENT_TYPE);
    response.getWriter().write( filteredContentMap.toString() );

    return ActionResult.OK;
}
 
開發者ID:DantaFramework,項目名稱:JahiaDF,代碼行數:54,代碼來源:PageContentModelToJSONServlet.java


注:本文中的org.apache.commons.codec.digest.DigestUtils.md5Hex方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。