在我的电脑的myeclipse的whnaproject项目下。可直接编译生成license.xml中所需要的授权码。 引用了spring-license-0.02.jar。
package com.whmetro.common.util.base;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.Map;
import org.apache.commons.lang.time.DateFormatUtils;
import com.software.pack.hi.HardwareInfoReader;
import com.software.pack.lic.DESEncrypt;
import com.software.pack.lic.LicenseInfo;
import com.software.pack.utils.common.DateHelper;
public class MyRSACoderTest2 {
public static void main(String[] args) throws Exception {
LicenseInfo lic = new LicenseInfo();
//lic.setCode("89456B46E82A20CE276D076EAA6E97D319E30269EAC9CDE9CC9A19CCC9E2FDE1E59DD1C9CFBFAF7A32ADF22BFC8B3207");
lic.setExpiration(DateHelper.parse("2016-12-31"));
lic.setUser("lcsoft");
/*System.out.println(encode("RAPEE-100-1412310703490741"));*/
//System.out.println("解密"+encode("ENCRR-655-6167865258945296"));
int s1=seed("RAPEE-100-1612310The software is copyright by lcsoft company ltd.lcsoft");
/* 说明:以上seed方法中"RAPEE-100-1612310"里的"1612310"是动态值,当之前lic.setExpiration(DateHelper.parse("2016-12-31"));设置为2016-12-31时,则动态值为1612310,当日期设置为2020-12-31时 ,则动态值未2012310 */
//System.out.println("解密"+seed("RAPEE-100-1612310The software is copyright by lcsoft company ltd.lcsoft"));
lic.setKey(encode("RAPEE-100-1612310"+s1));
/* 说明:以上encode方法中"RAPEE-100-1612310"里的"1612310"是动态值,当之前lic.setExpiration(DateHelper.parse("2016-12-31"));设置为2016-12-31时,则动态值为1612310,当日期设置为2020-12-31时 ,则动态值未2012310 */
System.out.println(lic.getKey());
//lic.setKey("ENCRR-655-6167865258945296");
String licDate = DateFormatUtils.format(DateHelper.parse("2016-12-31"), "yyyyMMdd");
System.out.println(licDate);
String key="lcsoftrap";
DESEncrypt desEncrypt = new DESEncrypt(key.getBytes());
String value = lic.getKey() + lic.getUser() + DateHelper.format(lic.getExpiration());
System.out.println(HardwareInfoReader.toHexString(desEncrypt.doEncrypt(value.getBytes("UTF-8"))));
}
public static String encode(String s) {
byte[] abyte0 = s.getBytes();
char[] ac = new char[s.length()];
int i = 0;
for (int k = abyte0.length; i < k; ++i) {
int j = abyte0[i];
if ((j >= 48) && (j <= 57))
j = (j - 48 + 5) % 10 + 48;
else if ((j >= 65) && (j <= 90))
j = (j - 65 + 13) % 26 + 65;
else if ((j >= 97) && (j <= 122))
j = (j - 97 + 13) % 26 + 97;
// System.out.println(abyte0[i]+"--"+j);
ac[i] = (char)j;
}
return String.valueOf(ac);
}
public static int seed(String s) {
int i = 0;
char[] ac = s.toCharArray();
int j = 0;
char news;
for (int k = ac.length; j < k; ++j) {
i = 31 * i + ac[j];
news=(char)ac[j];
//System.out.println(news);
}
// System.out.println(i);
return i;
}
}