淘先锋技术网

首页 1 2 3 4 5 6 7

java注册码怎么写?

平常我们都接触过软件注册,输入序列号、激活码、注册码、授权码;对于这些字符码到底代表什么含义不甚了解,但一般来说,这些字符码中都有几个特点:

1、唯一性,肯定是一个唯一的序列号,否则就会存在滥用的问题。

2、加密性,肯定是经过加密或者混乱的,防止大家自己生成序列号。

3、解密性,软件自身肯定可以解密,否则无法验证合法性。

4、可读性,序列号一般都比较标准,方便书写和记忆,所以一般都为数字和字母。

以下给出简单示例:

[java] view plaincopy

/**

* byte转哈希

* @param b

* @return

*/

public static String byte2hex(byte[] b) {

String hs = "";

String stmp = "";

for (int n = 0; n < b.length; n++) {

stmp = Integer.toHexString(b[n] & 0xFF);

if (stmp.length() == 1)

hs += ("0" + stmp);

else

hs += stmp;

}

return hs.toUpperCase();

}

/**

* 哈希转byte

* @param b

* @return

*/

public static byte[] hex2byte(byte[] b) {

if ((b.length % 2) != 0)

throw new IllegalArgumentException("长度不是偶数");

byte[] b2 = new byte[b.length / 2];

for (int n = 0; n < b.length; n += 2) {

String item = new String(b, n, 2);

b2[n / 2] = (byte) Integer.parseInt(item, 16);

}

return b2;

}

java书写,java注册码怎么写