com.huawei.dataconvert.util

// This is a Utility Class used for the Security Checking.
package com.huawei.dataconvert.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public final class SecurityUtil
{

private static final String MD5 = "MD5";

private static final String VALIDATE_KEY = "oracletest";

protected SecurityUtil(){

}

public static String getSecurityValue(String add)
{
String value = "";
MessageDigest alga = null;
try
{
alga = MessageDigest.getInstance(MD5);
} catch (NoSuchAlgorithmException e)
{
e.printStackTrace();
}
String key = VALIDATE_KEY + add;
alga.update(key.getBytes());
byte[] digesta = alga.digest();
value = byte2hex(digesta);
return value;
}

private static String byte2hex(byte[] b) // 二行制轉字符串
{
String hs = "";
String stmp = "";
for (int n = 0; n < b.length; n++)
{
stmp = (java.lang.Integer.toHexString(b[n] & 0XFF));
if (stmp.length() == 1)
hs = hs + "0" + stmp;
else
hs = hs + stmp;
if (n < b.length - 1)
hs = hs + ":";
}
return hs.toUpperCase();
}

/**
* @param args
*/
public static void main(String[] args)
{
String add = "10.132.42.521";
String value = SecurityUtil.getSecurityValue(add);
System.out.println(value);
}

}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章