public class LicenceCheckout {
校验码
原创
©著作权归作者所有:来自51CTO博客作者magicsa的原创作品,请联系作者获取转载授权,否则将追究法律责任
private String hexByte(byte b) {
String s = "000000" + Integer.toHexString(b);
return s.substring(s.length() - 2);
}
private String getSystemCode() {
try {
Enumeration<NetworkInterface> el = NetworkInterface.getNetworkInterfaces();
while (el.hasMoreElements()) {
NetworkInterface ni = el.nextElement();
byte[] mac = ni.getHardwareAddress();
if (null != mac && mac.length > 0) {
StringBuilder builder = new StringBuilder();
for (byte b : mac)
builder.append(hexByte(b));
return builder.toString();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
private String encode() {
try {
byte[] systemCode = getSystemCode().getBytes("UTF8");
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.update(systemCode);
String result = "";
byte[] temp;
temp = md5.digest(systemCode);
for (int i = 0; i < temp.length; i++) {
result += Integer.toHexString((0x000000ff & temp[i]) | 0xffffff00).substring(6);
}
return result;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
private String getLicence() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("licence")));
String line1 = br.readLine();
return line1;
}
public boolean hasAuthorized() {
try {
// 比较两个加密文件是否一致
if (encode().equals(getLicence().trim()))
return true;
System.out.println("授权失败!!!");
} catch (Exception e) {
System.out.println("授权验证失败,原因:" + e.getMessage());
}
return false;
}
public static void main(String[] args) throws SocketException {
LicenceCheckout t = new LicenceCheckout();
System.out.println(t.hasAuthorized());
}
}
上一篇:linux进入单用户模式
下一篇:dlink配置wds
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
循环冗余校验码
循环冗余校验码
计算机组成原理 校验码 其他