本文整理汇总了Java中org.apache.commons.codec.binary.Hex.encodeHex方法的典型用法代码示例。如果您正苦于以下问题:Java Hex.encodeHex方法的具体用法?Java Hex.encodeHex怎么用?Java Hex.encodeHex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.codec.binary.Hex
的用法示例。
在下文中一共展示了Hex.encodeHex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encodeInternal
import org.apache.commons.codec.binary.Hex; //导入方法依赖的package包/类
private String encodeInternal(String input)
{
if (!getEncodeHashAsBase64())
{
return new String(Hex.encodeHex(md4(input)));
}
byte[] encoded = Base64.encodeBase64(md4(input));
try
{
return new String(encoded, "UTF8");
}
catch (UnsupportedEncodingException e)
{
throw new RuntimeException("UTF8 not supported!", e);
}
}
示例2: checksum
import org.apache.commons.codec.binary.Hex; //导入方法依赖的package包/类
public static String checksum(Long domainId, List<ITransaction> list) {
xLogger.fine("Entered checksum: {0}", (list == null ? "NULL" : list.size()));
Iterator<ITransaction> it = list.iterator();
try {
MessageDigest md = MessageDigest.getInstance("MD5");
while (it.hasNext()) {
ITransaction trans = it.next();
if (trans.getDomainId() == null) {
trans.setDomainId(domainId);
}
byte[] fingerprint = trans.fingerprint();
if (fingerprint != null) {
md.update(fingerprint);
}
}
return new String(Hex.encodeHex(md.digest()));
} catch (Exception e) {
xLogger.warn("{0} when getting checksum: {1}", e.getClass().getName(), e.getMessage());
return null;
}
}
示例3: hexEncode
import org.apache.commons.codec.binary.Hex; //导入方法依赖的package包/类
/**
* Hex encode string.
*
* @param data the data
* @return the string
*/
public static String hexEncode(final byte[] data) {
try {
final char[] result = Hex.encodeHex(data);
return new String(result);
} catch (final Exception e) {
return null;
}
}
示例4: CommonHash
import org.apache.commons.codec.binary.Hex; //导入方法依赖的package包/类
public static String CommonHash(String p, String alg) throws NoSuchAlgorithmException
{
MessageDigest md = MessageDigest.getInstance(alg);
md.reset();
md.update(p.getBytes(Charset.forName("UTF-8")));
byte[] resBytes = md.digest();
String res = new String(Hex.encodeHex(resBytes));
return res;
}
示例5: encodeHex
import org.apache.commons.codec.binary.Hex; //导入方法依赖的package包/类
public static String encodeHex(String normalString, String charset) {
if (normalString == null) {
return null;
}
if (charset == null) {
charset = CHARSET_DEFAULT;
}
String hexString = null;
try {
hexString = new String(Hex.encodeHex(normalString.getBytes(charset)));
} catch (Exception e) {
e.printStackTrace();
}
return hexString;
}
示例6: sha256
import org.apache.commons.codec.binary.Hex; //导入方法依赖的package包/类
public static String sha256(String plaintext) {
try {
MessageDigest md = MessageDigest.getInstance("SHA-256");
return new String(Hex.encodeHex(md.digest(plaintext.getBytes())));
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
示例7: shouldEncodeWithMd5ThenHex
import org.apache.commons.codec.binary.Hex; //导入方法依赖的package包/类
@Test
public void shouldEncodeWithMd5ThenHex() throws NoSuchAlgorithmException {
String input = "My input string";
MessageDigest md5 = MessageDigest.getInstance("MD5");
String expected = new String(Hex.encodeHex(md5.digest(input.getBytes())));
assertThat(new Encoder(input).md5().hex().string(), is(expected));
}
示例8: encodeHexAsBase64
import org.apache.commons.codec.binary.Hex; //导入方法依赖的package包/类
@Test
public void encodeHexAsBase64() {
String value = "ABCDEF";
String valueHex = new String(Hex.encodeHex(value.getBytes(Charsets.UTF_8)));
assertThat(valueHex, is(equalTo("414243444546")));
String valueBase64 = CryptotoolUtils.encodeHexAsBase64(valueHex);
assertThat(valueBase64, is(equalTo("QUJDREVG")));
}
示例9: SecretKeySpec
import org.apache.commons.codec.binary.Hex; //导入方法依赖的package包/类
public static String bьь044Cь044Cь(String str, String str2) {
try {
byte[] bytes = str.getBytes(UrlUtils.UTF8);
Mac instance = Mac.getInstance("HmacSHA256");
instance.init(new SecretKeySpec(str2.getBytes(UrlUtils.UTF8), "HmacSHA256"));
bytes = instance.doFinal(bytes);
if (((bСССС04210421 + bС0421СС04210421) * bСССС04210421) % b04210421СС04210421 != b0421ССС04210421) {
bСССС04210421 = 84;
b0421ССС04210421 = b0421С0421С04210421();
}
return new String(Hex.encodeHex(bytes));
} catch (Exception e) {
return "null";
}
}
示例10: getMD5
import org.apache.commons.codec.binary.Hex; //导入方法依赖的package包/类
/**
* Generates Hex encoded MD5 hash for the given string
*
* @param payLoad - String/Text
* @return hex coded md5 for the given payLoad.
*/
public static String getMD5(String payLoad) {
try {
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
byte[] digestedPayLoad = messageDigest.digest(payLoad.getBytes(StandardCharsets.UTF_8));
return new String(Hex.encodeHex(digestedPayLoad));
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
示例11: createSliceKey
import org.apache.commons.codec.binary.Hex; //导入方法依赖的package包/类
public static String createSliceKey(Long domainId, Date d, String objectType, String objectId,
String dt, String dv, String tz) {
MessageDigest md = null;
if (d != null && domainId != null && objectType != null && objectId != null && dt != null
&& dv != null) {
try {
Calendar cal = GregorianCalendar.getInstance();
if (tz != null) {
cal.setTimeZone(TimeZone.getTimeZone(tz));
}
cal.setTime(d);
String timeStr = String.valueOf(cal.get(Calendar.DATE)) +
String.valueOf(cal.get(Calendar.MONTH)) +
String.valueOf(cal.get(Calendar.YEAR));
md = MessageDigest.getInstance("MD5");
md.update(timeStr.getBytes()); // date
md.update(domainId.toString().getBytes()); // domain Id
md.update(objectType.getBytes()); // object type
md.update(objectId.getBytes()); // object Id
md.update(dt.getBytes()); // dim. type
md.update(dv.getBytes()); // dim. value
} catch (NoSuchAlgorithmException e) {
XLog.getLog(Slice.class).warn("Exception: No such algorithm: {0}", e.getMessage());
}
}
if (md != null) {
byte[] bytes = md.digest();
if (bytes != null) {
return new String(Hex.encodeHex(bytes));
}
}
return null;
}
示例12: createActiveCountsStatsStoreKey
import org.apache.commons.codec.binary.Hex; //导入方法依赖的package包/类
public static String createActiveCountsStatsStoreKey(Long domainId, Date d, String objectType,
String objectId, String dt, String dv) {
MessageDigest md = null;
if (d != null && domainId != null && objectType != null && objectId != null && dt != null
&& dv != null) {
try {
// Get the time string
Calendar cal = GregorianCalendar.getInstance();
cal.setTime(d);
String timeStr = String.valueOf(cal.get(Calendar.DATE)) +
String.valueOf(cal.get(Calendar.MONTH)) +
String.valueOf(cal.get(Calendar.YEAR));
md = MessageDigest.getInstance("MD5");
md.update(timeStr.getBytes()); // date
md.update(domainId.toString().getBytes()); // domain Id
md.update(objectType.getBytes()); // object type
md.update(objectId.getBytes()); // object Id
md.update(dt.getBytes()); // dim. type
md.update(dv.getBytes()); // dim. value
} catch (NoSuchAlgorithmException e) {
XLog.getLog(Slice.class).warn("Exception: No such algorithm: {0}", e.getMessage());
}
}
if (md != null) {
byte[] bytes = md.digest();
if (bytes != null) {
return new String(Hex.encodeHex(bytes));
}
}
return null;
}
示例13: hex
import org.apache.commons.codec.binary.Hex; //导入方法依赖的package包/类
public static String hex(byte[] buffer){
return new String(Hex.encodeHex(buffer));
}
示例14: encodeHex
import org.apache.commons.codec.binary.Hex; //导入方法依赖的package包/类
/**
* Hex编码.
*/
public static String encodeHex(byte[] input) {
return new String(Hex.encodeHex(input));
}
示例15: generateEncodedString
import org.apache.commons.codec.binary.Hex; //导入方法依赖的package包/类
public static String generateEncodedString(String userToken, String userPrivateKey, String truckId,
int userIdMaxLen, int truckIdMaxLen, int totoCodeSize) throws NoSuchAlgorithmException,UnsupportedEncodingException {
// Random
int random = getRandom(1, 9) * 10 + getRandom(0, 10);
// Truck ID info
String truckIdNew = "000000000000" + truckId;
truckIdNew = truckIdNew.substring(truckIdNew.length() - truckIdMaxLen);
// UTC TimeStamp
long lnCurrentTime = System.currentTimeMillis();
long timeStamp = lnCurrentTime / 1000 / 30;
timeStamp = timeStamp * 100 + random;
// Encode User Info
MessageDigest md = MessageDigest.getInstance("SHA-256");
String userInfo = new String(
Hex.encodeHex(md.digest((userToken + truckId + userPrivateKey).getBytes("utf-8"))));
// Time Step
String timeStep = Long.toHexString(timeStamp).toUpperCase();
// TOTP Code
String totpCode = generateTOTP(userInfo, timeStep, String.valueOf(totoCodeSize), HMAC_SHA256);
String totpCodeNew = (new StringBuilder(totpCode)).reverse().toString();
// TOTP Code2
String tempInfo = new String(Hex.encodeHex(md.digest((totpCode + random + totpCodeNew).getBytes("utf-8"))));
String timeStempNew = Long.toHexString(Long.parseLong(random + totpCode + totpCodeNew, 10)).toUpperCase();
String totpCode2 = generateTOTP(tempInfo, timeStempNew, "8", HMAC_SHA256);
String totpCode2New = (new StringBuilder(totpCode2)).reverse().toString();
totpCode2 += totpCode2New;
totpCode2 = totpCode2.substring(0,
userIdMaxLen + truckIdMaxLen - (String.valueOf(random)).length() - totoCodeSize);
// Encoded User's Token
long encodedToken = Long.parseLong(userToken + truckIdNew, 10)
+ Long.parseLong(random + totpCodeNew + totpCode2, 10);
String strEncodedToken = String.valueOf(encodedToken);
int padding = getRandom(0, 10);
if (strEncodedToken.length() <= userIdMaxLen + truckIdMaxLen) {
if (padding % 2 == 1) {
padding += 1;
}
} else {
if (padding % 2 == 0) {
padding += 1;
}
}
padding = padding % 10;
strEncodedToken = padding + strEncodedToken.substring(strEncodedToken.length() - userIdMaxLen - truckIdMaxLen);
// Offline Authorization Code
StringBuilder oac = new StringBuilder();
oac.append(random);
oac.append(totpCode);
oac.append(strEncodedToken);
String oacLine = oac.toString();
return oacLine;
}