JavaMD5[通俗易懂]

2022-09-14 11:19:35 浏览数 (1)

大家好,又见面了,我是你们的朋友全栈君。

public class CalPrivateKey {

public static void main(String[] args)

{

String appKey = “cee56d5722ea3afbef390e4dd1beda77”;

String appSecret = “010b02dd9b580f116c5352c5ecb7ca92”;

String privateKey = getHash(appSecret “#” appKey);

System.out.println(privateKey);

}

public static String getHash(String uri)

{

MessageDigest mDigest;

try

{

mDigest = MessageDigest.getInstance(“MD5”);

mDigest.update(uri.getBytes());

byte d[] = mDigest.digest();

return toHexString(d);

}

catch (NoSuchAlgorithmException e)

{

e.printStackTrace();

}

return uri;

}

private static final char HEX_DIGITS[] =

{

‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’

};

public static String toHexString(byte[] b)

{ // String to byte

StringBuilder sb = new StringBuilder(b.length * 2);

for (int i = 0; i < b.length; i )

{

sb.append(HEX_DIGITS[(b[i] & 0xf0) >>> 4]);

sb.append(HEX_DIGITS[b[i] & 0x0f]);

}

return sb.toString();

}

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/158999.html原文链接:https://javaforall.cn

0 人点赞