资源简介

使用truelicense实现用于JAVA工程license机制(包括license生成和验证)

资源截图

代码片段和文件信息

package cn.melina.license;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Properties;
import java.util.prefs.Preferences;
import javax.security.auth.x500.X500Principal;
import de.schlichtherle.license.CipherParam;
import de.schlichtherle.license.DefaultCipherParam;
import de.schlichtherle.license.DefaultKeyStoreParam;
import de.schlichtherle.license.DefaultLicenseParam;
import de.schlichtherle.license.KeyStoreParam;
import de.schlichtherle.license.LicenseContent;
import de.schlichtherle.license.LicenseParam;
import de.schlichtherle.license.LicenseManager;

/**
 * CreateLicense
 * @author melina
 */
public class CreateLicense {
//common param
private static String PRIVATEALIAS = ““;
private static String KEYPWD = ““;
private static String STOREPWD = ““;
private static String SUBJECT = ““;
private static String licPath = ““;
private static String priPath = ““;
//license content
private static String issuedTime = ““;
private static String notBefore = ““;
private static String notAfter = ““;
private static String consumerType = ““;
private static int consumerAmount = 0;
private static String info = ““;
// 为了方便直接用的API里的例子
// X500Princal是一个证书文件的固有格式,详见API
private final static X500Principal DEFAULTHOLDERANDISSUER = new X500Principal(
“CN=Duke、OU=JavaSoft、O=Sun Microsystems、C=US“);

public void setParam(String propertiesPath) {
// 获取参数
Properties prop = new Properties();
InputStream in = getClass().getResourceAsStream(propertiesPath);
try {
prop.load(in);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
PRIVATEALIAS = prop.getProperty(“PRIVATEALIAS“);
KEYPWD = prop.getProperty(“KEYPWD“);
STOREPWD = prop.getProperty(“STOREPWD“);
SUBJECT = prop.getProperty(“SUBJECT“);
KEYPWD = prop.getProperty(“KEYPWD“);
licPath = prop.getProperty(“licPath“);
priPath = prop.getProperty(“priPath“);
//license content
issuedTime = prop.getProperty(“issuedTime“);
notBefore = prop.getProperty(“notBefore“);
notAfter = prop.getProperty(“notAfter“);
consumerType = prop.getProperty(“consumerType“);
consumerAmount = Integer.valueOf(prop.getProperty(“consumerAmount“));
info = prop.getProperty(“info“);

}

public boolean create() {
try {
/************** 证书发布者端执行 ******************/
LicenseManager licenseManager = LicenseManagerHolder
.getLicenseManager(initLicenseParams0());
licenseManager.store((createLicenseContent()) new File(licPath));
} catch (Exception e) {
e.printStackTrace();
System.out.println(“客户端证书生成失败!“);
return false;
}
System.out.println(“服务器端生成证书成功!“);
return true;
}

// 返回生成证书时需要的参数
private static LicenseParam initLicenseParams0() {
Preferences preference = Preferences
.userNodeForPacka

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2014-04-03 12:32  LicenseCreate\
     文件         533  2014-04-03 12:32  LicenseCreate\.classpath
     文件         389  2014-04-03 12:32  LicenseCreate\.project
     目录           0  2014-04-03 12:32  LicenseCreate\.settings\
     文件         598  2014-04-03 12:32  LicenseCreate\.settings\org.eclipse.jdt.core.prefs
     目录           0  2014-04-03 12:32  LicenseCreate\.svn\
     文件           3  2014-04-03 12:31  LicenseCreate\.svn\entries
     文件           3  2014-04-03 12:31  LicenseCreate\.svn\format
     目录           0  2014-04-03 12:32  LicenseCreate\.svn\pristine\
     目录           0  2014-04-03 12:32  LicenseCreate\.svn\pristine\17\
     文件         598  2014-04-03 12:32  LicenseCreate\.svn\pristine\17\1738f633fc4a9029a9b29c54a7d3fc9dfb4ca9cf.svn-base
     目录           0  2014-04-03 12:32  LicenseCreate\.svn\pristine\1a\
     文件         533  2014-04-03 12:32  LicenseCreate\.svn\pristine\1a\1af388cb24631a1af8db5c877ad752e3529e09f9.svn-base
     目录           0  2014-04-03 12:31  LicenseCreate\.svn\pristine\4a\
     文件         389  2014-04-03 12:31  LicenseCreate\.svn\pristine\4a\4a8aea65d1b2e6de249bfec318cb4d5080acfbb1.svn-base
     目录           0  2014-04-03 12:31  LicenseCreate\.svn\pristine\4f\
     文件       44655  2014-04-03 12:31  LicenseCreate\.svn\pristine\4f\4fbbb1d34e2f672376ab9f95e2dc9804f6d2d0b5.svn-base
     目录           0  2014-04-03 12:32  LicenseCreate\.svn\pristine\77\
     文件        4474  2014-04-03 12:32  LicenseCreate\.svn\pristine\77\77c149e3a67c176c13fc3a0b485d90e3d2349f76.svn-base
     目录           0  2014-04-03 12:32  LicenseCreate\.svn\pristine\7c\
     文件         307  2014-04-03 12:32  LicenseCreate\.svn\pristine\7c\7c5903a1c73ee235e345acc1150868c926cf8a34.svn-base
     目录           0  2014-04-03 12:32  LicenseCreate\.svn\pristine\81\
     文件        4941  2014-04-03 12:32  LicenseCreate\.svn\pristine\81\81678fe8928918910a0e46b41800949ceb25a0b6.svn-base
     目录           0  2014-04-03 12:32  LicenseCreate\.svn\pristine\96\
     文件         773  2014-04-03 12:32  LicenseCreate\.svn\pristine\96\9643deec16fdc053bd46882f33bd3eaeb6e5522a.svn-base
     目录           0  2014-04-03 12:32  LicenseCreate\.svn\pristine\9c\
     文件      259600  2014-04-03 12:32  LicenseCreate\.svn\pristine\9c\9cd61d269c88f9fb0eb36cea1efcd596ab74772f.svn-base
     目录           0  2014-04-03 12:32  LicenseCreate\.svn\pristine\b6\
     文件         656  2014-04-03 12:32  LicenseCreate\.svn\pristine\b6\b6b6dc92cb0303c886686fa829c23548b9d382dd.svn-base
     目录           0  2014-04-03 12:32  LicenseCreate\.svn\pristine\ba\
     文件        7439  2014-04-03 12:32  LicenseCreate\.svn\pristine\ba\bac2335b585cb29bef3e555ed30a1d37eedf28e3.svn-base
............此处省略103个文件信息

评论

共有 条评论