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


Java DigestUtils.sha1Hex方法代碼示例

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


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

示例1: blur

import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
@RequestMapping(value = "/blur", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<InputStreamResource> blur(@RequestParam("source") String sourceUrl, HttpServletResponse response) {
    if (!StringUtils.startsWithAny(sourceUrl, ALLOWED_PREFIX)) {
        return ResponseEntity.badRequest().build();
    }

    String hash = DigestUtils.sha1Hex(sourceUrl);

    try {
        ImageInfo info = readCached(hash);
        if (info == null) {
            info = renderImage(sourceUrl);
            if (info != null) {
                saveCached(hash, info);
            }
        }
        if (info != null) {
            return ResponseEntity.ok()
                    .contentLength(info.contentLength)
                    .contentType(MediaType.IMAGE_JPEG)
                    .body(new InputStreamResource(info.inputStream));
        }
    } catch (IOException e) {
        // fall down
    }
    return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
 
開發者ID:GoldRenard,項目名稱:JuniperBotJ,代碼行數:29,代碼來源:BlurImageController.java

示例2: sendMessage

import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
public void sendMessage (final String data) {
	FirebaseMessaging fm = FirebaseMessaging.getInstance();

	String token = FirebaseInstanceId.getInstance().getToken();
	String msgID = DigestUtils.sha1Hex(token + System.currentTimeMillis());
	String SENDER_ID = "someID";

	RemoteMessage.Builder RMBuilder =
	new RemoteMessage.Builder(SENDER_ID + "@gcm.googleapis.com");
	RMBuilder.setMessageId(msgID);

	Map<String, Object> mapData = Utils.jsonToMap(data);

	for (Map.Entry<String, Object> entry : mapData.entrySet()) {
		RMBuilder.addData(entry.getKey(), entry.getValue().toString());
	}

	fm.send(RMBuilder.build());
}
 
開發者ID:FrogSquare,項目名稱:GodotFireBase,代碼行數:20,代碼來源:Notification.java

示例3: sha

import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
/**
 * @param message {@link String}
 * @param type    {@link HashType}
 * @return {@link String}
 */
private static String sha(String message, HashType type) {
    switch (type) {
        case SHA1:
            return DigestUtils.sha1Hex(message);
        case SHA256:
            return DigestUtils.sha256Hex(message);
        case SHA512:
            return DigestUtils.sha512Hex(message);
        default:
            return DigestUtils.sha256Hex(message);
    }
}
 
開發者ID:farchanjo,項目名稱:webcron,代碼行數:18,代碼來源:HashUtils.java

示例4: sha1

import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
public static String sha1(String str){
    String s = null;
    try {
        byte[] data = str.getBytes("UTF-8");

        s = DigestUtils.sha1Hex(data);
    }catch (Exception ex){
        ex.printStackTrace();
    }

    return s;
}
 
開發者ID:noear,項目名稱:JtSQL,代碼行數:13,代碼來源:EncryptUtil.java

示例5: ResourceBundle

import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
private ResourceBundle(ResourceType resourceType, File virtualFile, String key) {
	this.resourceType= resourceType; 
	this.virtualFile = virtualFile;
	key = key.replaceFirst("(.*?)/_private/(?:flashupdate|mobile)/", "$1/DisplayObjects/mobile/");
	key = DigestUtils.md5Hex(key) + DigestUtils.sha1Hex(key) + "." + resourceType.name();
	cacheFile = new File(minificationCacheDirectory, key);
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:8,代碼來源:MinificationManager.java

示例6: checkLogin

import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
private UserEntity checkLogin(String email, String password) {
	password = (DigestUtils.sha1Hex(password));
	if (email != null && !email.isEmpty() && !password.isEmpty()) {
		UserEntity userEntity = userDao.findByEmail(email);
		if (userEntity != null) {
			if (password.equals(userEntity.getPassword())) {
				return userEntity;
			}
		}
	}
	return null;
}
 
開發者ID:SoapboxRaceWorld,項目名稱:soapbox-race-core,代碼行數:13,代碼來源:PromoCodeBO.java

示例7: genWithAmple

import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
/**
 * 用&串接arr參數,生成sha1 digest
 */
public static String genWithAmple(String... arr) {
  Arrays.sort(arr);
  StringBuilder sb = new StringBuilder();
  for (int i = 0; i < arr.length; i++) {
    String a = arr[i];
    sb.append(a);
    if (i != arr.length - 1) {
      sb.append('&');
    }
  }
  return DigestUtils.sha1Hex(sb.toString());
}
 
開發者ID:11590692,項目名稱:Wechat-Group,代碼行數:16,代碼來源:SHA1.java

示例8: __buildJsApiConfigStr

import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
private String __buildJsApiConfigStr(String appId, String jsapiTicket, String url, String timestamp, String noncestr, boolean debug) throws Exception {
    String _signature = "jsapi_ticket=" + jsapiTicket + "&" + "noncestr=" + noncestr + "&" + "timeStamp=" + timestamp + "&" + "url=" + url;
    _signature = DigestUtils.sha1Hex(_signature);
    //
    JSONObject _json = new JSONObject();
    _json.put("debug", debug);
    _json.put("appId", appId);
    _json.put("timestamp", timestamp);
    _json.put("nonceStr", noncestr);
    _json.put("signature", _signature);
    _json.put("jsApiList", new String[]{"chooseWXPay"});
    //
    return _json.toJSONString();
}
 
開發者ID:suninformation,項目名稱:ymate-payment-v2,代碼行數:15,代碼來源:WxPayJsApiController.java

示例9: generateUniqueId

import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
public static String generateUniqueId(String metrics) {    // 相同的metrics定會產生相同的uniqueID
	String metricsID = DigestUtils.sha1Hex(metrics + atomicInteger.incrementAndGet());    // 40個字符組成
	char[] _chars = metricsID.toCharArray();
	StringBuilder sb = new StringBuilder();
	for(int i = 0; i < _chars.length; i ++ ) {
		if(i % 10 == 0 && i != 0) {	// 10、20和30
			sb.append("-");
		}
		sb.append(String.valueOf(_chars[i]));
	}
	
	return sb.toString();
}
 
開發者ID:dk900912,項目名稱:alerts-forwarder,代碼行數:14,代碼來源:AppUtils.java

示例10: makeSignBySinpleFieldList

import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
/**
 * 根據SinpleField列表生成簽名
 *
 * 加2個參數   delimiter,caseConvert
 *
 * @param fieldPaireds SinpleField的列表
 * @param salt partnerApiKey
 * @return 生成的簽名字符串
 */
private static String makeSignBySinpleFieldList(List<FieldPaired> fieldPaireds, String salt,
    Boolean excludeKeyParameter, SignatureAlgorithmic algorithmic, String saltParameterPrefix,
    String charset, CaseControl caseControl, String delimiter) {
  List<String> list = fieldPaireds.stream()
      .sorted(new AsciiSortedComparator<>(FieldPaired::getProperty)).map(
          FieldPaired::toString).collect(Collectors.toList());

  //在對象上添加特殊屬性, 當不排除時添加
  if (!excludeKeyParameter) {
    if (StringUtils.isEmpty(saltParameterPrefix)) {
      throw new RuntimeException("指定了需要添加KEY=到salt前麵, 卻沒有指定前前綴, 請檢查官方文檔,再做相應調整");
    }
    list.add(saltParameterPrefix + salt);
  }

  // 未加密字符串
  String unencrypted = "";
  try {
    unencrypted = new String(String.join(delimiter, list).getBytes(), charset);
    //將salt添加到最後麵
    if (!StringUtils.isEmpty(salt)) {
      if (excludeKeyParameter) {
        unencrypted += salt;
      }
    }
    log.debug("Unencrypted String is: {}", unencrypted);
  } catch (Exception e) {
    e.printStackTrace();
  }

  String result = "";
  switch (algorithmic) {
    case MD2:
      result = DigestUtils.md2Hex(unencrypted);
      break;
    case MD5:
      result = DigestUtils.md5Hex(unencrypted);
      break;
    case SHA1:
      result = DigestUtils.sha1Hex(unencrypted);
      break;
    case SHA256:
      result = DigestUtils.sha256Hex(unencrypted);
      break;
    case SHA384:
      result = DigestUtils.sha384Hex(unencrypted);
      break;
    case SHA512:
      result = DigestUtils.sha512Hex(unencrypted);
      break;
    default:
      throw new RuntimeException("不支持的簽名類型");
  }

  if (null != caseControl) {
    switch (caseControl) {
      case TO_LOWER_CASE:
        result = result.toLowerCase();
        break;
      case TO_UPPER_CASE:
        result = result.toUpperCase();
        break;
    }
  }

  log.debug("Encrypted Signature is: {}", result);
  return result;

}
 
開發者ID:minlia-projects,項目名稱:minlia-iot,代碼行數:79,代碼來源:XmlSignatureAnnotationHelper.java

示例11: checkHash

import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
private boolean checkHash(String p_190113_1_, File p_190113_2_)
{
    try
    {
        String s = DigestUtils.sha1Hex((InputStream)(new FileInputStream(p_190113_2_)));

        if (p_190113_1_.isEmpty())
        {
            LOGGER.info("Found file {} without verification hash", new Object[] {p_190113_2_});
            return true;
        }

        if (s.toLowerCase(java.util.Locale.ROOT).equals(p_190113_1_.toLowerCase(java.util.Locale.ROOT)))
        {
            LOGGER.info("Found file {} matching requested hash {}", new Object[] {p_190113_2_, p_190113_1_});
            return true;
        }

        LOGGER.warn("File {} had wrong hash (expected {}, found {}).", new Object[] {p_190113_2_, p_190113_1_, s});
    }
    catch (IOException ioexception)
    {
        LOGGER.warn("File {} couldn\'t be hashed.", new Object[] {p_190113_2_, ioexception});
    }

    return false;
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:28,代碼來源:ResourcePackRepository.java

示例12: checkHash

import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
private boolean checkHash(String p_190113_1_, File p_190113_2_)
{
    try
    {
        String s = DigestUtils.sha1Hex((InputStream)(new FileInputStream(p_190113_2_)));

        if (p_190113_1_.isEmpty())
        {
            LOGGER.info("Found file {} without verification hash", new Object[] {p_190113_2_});
            return true;
        }

        if (s.toLowerCase().equals(p_190113_1_.toLowerCase()))
        {
            LOGGER.info("Found file {} matching requested hash {}", new Object[] {p_190113_2_, p_190113_1_});
            return true;
        }

        LOGGER.warn("File {} had wrong hash (expected {}, found {}).", new Object[] {p_190113_2_, p_190113_1_, s});
    }
    catch (IOException ioexception)
    {
        LOGGER.warn("File {} couldn\'t be hashed.", new Object[] {p_190113_2_, ioexception});
    }

    return false;
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:28,代碼來源:ResourcePackRepository.java

示例13: encryptSHA

import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
/**
 * 將字符串 SHA 加密
 */
public static String encryptSHA(String str) {
    return DigestUtils.sha1Hex(str);
}
 
開發者ID:smxc,項目名稱:garlicts,代碼行數:7,代碼來源:CodecUtil.java

示例14: UserVO

import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
public UserVO(String email, String password) {
	this.email = email;
	this.password = password;
	this.shaPassword = DigestUtils.sha1Hex(password);
}
 
開發者ID:SoapboxRaceWorld,項目名稱:soapbox-race-jlauncher,代碼行數:6,代碼來源:UserVO.java

示例15: buildAuthorizationStr

import org.apache.commons.codec.digest.DigestUtils; //導入方法依賴的package包/類
public String buildAuthorizationStr(HttpMethodName methodName, String resouce_path,
        Map<String, String> headerMap, Map<String, String> paramMap, COSCredentials cred,
        Date expiredTime) {

    if (isAnonymous(cred)) {
        return null;
    }

    Map<String, String> signHeaders = buildSignHeaders(headerMap);
    // 簽名中的參數和http 頭部 都要進行字符串排序
    TreeMap<String, String> sortedSignHeaders = new TreeMap<>();
    TreeMap<String, String> sortedParams = new TreeMap<>();

    sortedSignHeaders.putAll(signHeaders);
    sortedParams.putAll(paramMap);

    String qHeaderListStr = buildSignMemberStr(sortedSignHeaders);
    String qUrlParamListStr = buildSignMemberStr(sortedParams);
    String qKeyTimeStr, qSignTimeStr;
    qKeyTimeStr = qSignTimeStr = buildTimeStr(expiredTime);
    String signKey = HmacUtils.hmacSha1Hex(cred.getCOSSecretKey(), qKeyTimeStr);
    String formatMethod = methodName.toString().toLowerCase();
    String formatUri = resouce_path;
    String formatParameters = formatMapToStr(sortedParams);
    String formatHeaders = formatMapToStr(sortedSignHeaders);

    String formatStr = new StringBuilder().append(formatMethod).append(LINE_SEPARATOR)
            .append(formatUri).append(LINE_SEPARATOR).append(formatParameters)
            .append(LINE_SEPARATOR).append(formatHeaders).append(LINE_SEPARATOR).toString();
    String hashFormatStr = DigestUtils.sha1Hex(formatStr);
    String stringToSign = new StringBuilder().append(Q_SIGN_ALGORITHM_VALUE)
            .append(LINE_SEPARATOR).append(qSignTimeStr).append(LINE_SEPARATOR)
            .append(hashFormatStr).append(LINE_SEPARATOR).toString();
    String signature = HmacUtils.hmacSha1Hex(signKey, stringToSign);

    String authoriationStr = new StringBuilder().append(Q_SIGN_ALGORITHM_KEY).append("=")
            .append(Q_SIGN_ALGORITHM_VALUE).append("&").append(Q_AK).append("=")
            .append(cred.getCOSAccessKeyId()).append("&").append(Q_SIGN_TIME).append("=")
            .append(qSignTimeStr).append("&").append(Q_KEY_TIME).append("=").append(qKeyTimeStr)
            .append("&").append(Q_HEADER_LIST).append("=").append(qHeaderListStr).append("&")
            .append(Q_URL_PARAM_LIST).append("=").append(qUrlParamListStr).append("&")
            .append(Q_SIGNATURE).append("=").append(signature).toString();
    return authoriationStr;
}
 
開發者ID:tencentyun,項目名稱:cos-java-sdk-v5,代碼行數:45,代碼來源:COSSigner.java


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