Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
license-generator
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄营
license-generator
Commits
e1f34e91
Commit
e1f34e91
authored
Aug 22, 2025
by
liuzz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
license
parent
cd60d6a2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
31 deletions
+56
-31
LicenseGenerator.java
src/main/java/com/tbyf/license/LicenseGenerator.java
+12
-4
LicenseParams.java
src/main/java/com/tbyf/license/LicenseParams.java
+42
-25
LicenseGeneratorTest.java
src/test/java/com/tbyf/license/LicenseGeneratorTest.java
+2
-2
No files found.
src/main/java/com/tbyf/license/LicenseGenerator.java
View file @
e1f34e91
...
@@ -10,11 +10,12 @@ import global.namespace.truelicense.obfuscate.ObfuscatedString;
...
@@ -10,11 +10,12 @@ import global.namespace.truelicense.obfuscate.ObfuscatedString;
import
global.namespace.truelicense.v4.V4
;
import
global.namespace.truelicense.v4.V4
;
import
javax.security.auth.x500.X500Principal
;
import
javax.security.auth.x500.X500Principal
;
import
java.util.Date
;
public
class
LicenseGenerator
{
public
class
LicenseGenerator
{
private
static
final
String
SUBJECT
=
"HIP"
;
private
static
final
String
SUBJECT
=
"HIP"
;
private
static
final
String
DISTINGUISHED_NAME
=
"CN=TBYF
HIP
"
;
private
static
final
String
DISTINGUISHED_NAME
=
"CN=TBYF"
;
private
static
final
String
KEY_STORE_FILE
=
"private.ks"
;
private
static
final
String
KEY_STORE_FILE
=
"private.ks"
;
private
static
final
LicenseManagementContext
_managementContext
=
V4
private
static
final
LicenseManagementContext
_managementContext
=
V4
...
@@ -55,9 +56,16 @@ public class LicenseGenerator {
...
@@ -55,9 +56,16 @@ public class LicenseGenerator {
public
void
generate
(
LicenseParams
params
)
throws
LicenseManagementException
{
public
void
generate
(
LicenseParams
params
)
throws
LicenseManagementException
{
VendorLicenseManager
manager
=
manager
();
VendorLicenseManager
manager
=
manager
();
License
license
=
manager
.
parameters
().
licenseFactory
().
license
();
License
license
=
manager
.
parameters
().
licenseFactory
().
license
();
license
.
setNotBefore
(
params
.
getStartDate
());
license
.
setConsumerAmount
(
1
);
// 消费者数量
license
.
setNotAfter
(
params
.
getExpirationDate
());
license
.
setConsumerType
(
""
);
// business-企业 personally-个人 project-项目
license
.
setExtra
(
params
.
getMAC
());
license
.
setHolder
(
new
X500Principal
(
DISTINGUISHED_NAME
));
// 许可证持有者的唯一标识
license
.
setIssuer
(
new
X500Principal
(
DISTINGUISHED_NAME
));
// 许可证颁发者的唯一标识
license
.
setInfo
(
"TBYF HIP License"
);
// 面向用户的说明文本
license
.
setIssued
(
new
Date
());
// 许可证颁发日期
license
.
setNotBefore
(
new
Date
());
// 许可证生效日期
license
.
setNotAfter
(
new
Date
());
// 许可证失效日期
license
.
setSubject
(
"CentralPharmacy-v1"
);
// 许可证管理的目标(如应用名称和版本范围 "MyApp 1.X")
license
.
setExtra
(
params
.
getMAC
());
// 私有数据,如MAC地址
manager
.
generateKeyFrom
(
license
)
manager
.
generateKeyFrom
(
license
)
.
saveTo
(
BIOS
.
file
(
params
.
getLicensePath
()));
.
saveTo
(
BIOS
.
file
(
params
.
getLicensePath
()));
}
}
...
...
src/main/java/com/tbyf/license/LicenseParams.java
View file @
e1f34e91
package
com
.
tbyf
.
license
;
package
com
.
tbyf
.
license
;
import
lombok.
Builder
;
import
lombok.
Data
;
import
lombok.Getter
;
import
lombok.Getter
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.Date
;
@
Builder
@
Data
public
class
LicenseParams
{
public
class
LicenseParams
{
@Getter
@Getter
private
String
licensePath
;
private
String
licensePath
;
/**
* 开始日期
*/
private
Date
startDate
;
private
Date
startDate
;
// 有效天数
/**
* license有效天数
*/
private
int
validity
;
private
int
validity
;
private
Date
expirationDate
;
/**
* 授权数量
@Getter
*/
private
String
MAC
;
// MAC硬件地址
private
int
amount
=
1
;
public
Date
getExpirationDate
()
{
/**
Date
ed
=
this
.
expirationDate
;
* 授权类型 business-企业 personally-个人 project-项目
return
null
!=
ed
?
ed
:
calculateExpirationDate
();
*/
}
private
String
type
=
"business"
;
public
Date
getStartDate
()
{
/**
Date
sd
=
this
.
startDate
;
* 授权信息
return
null
!=
sd
?
sd
:
new
Date
();
*/
}
private
String
info
=
"tbyf hip license"
;
private
Date
calculateExpirationDate
()
{
/**
Calendar
calendar
=
Calendar
.
getInstance
();
* 应用名称
calendar
.
setTime
(
getStartDate
());
*/
calendar
.
add
(
Calendar
.
DAY_OF_YEAR
,
this
.
validity
);
private
String
appName
;
return
calendar
.
getTime
();
}
/**
* 授权使用的版本
*/
private
String
version
;
/**
* 授权使用的MAC地址, *为所有mac都支持
*/
private
String
mac
=
"*"
;
/**
* 需要限制的url, *为所有url都支持
*/
private
String
urls
;
}
}
src/test/java/com/tbyf/license/LicenseGeneratorTest.java
View file @
e1f34e91
...
@@ -14,10 +14,10 @@ class LicenseGeneratorTest {
...
@@ -14,10 +14,10 @@ class LicenseGeneratorTest {
LicenseGenerator
licenseGenerator
=
new
LicenseGenerator
();
LicenseGenerator
licenseGenerator
=
new
LicenseGenerator
();
licenseGenerator
.
generate
(
licenseGenerator
.
generate
(
LicenseParams
.
builder
()
LicenseParams
.
builder
()
.
licensePath
(
"
xyz
.lic"
)
.
licensePath
(
"
dev
.lic"
)
.
validity
(
3
)
.
validity
(
3
)
// .expirationDate(toDate("2024-01-11 15:12:00"))
// .expirationDate(toDate("2024-01-11 15:12:00"))
.
MAC
(
"
CC-F9-E4-97-CA-48,CC-F9-E4-97-CA-49, CC-F9-E4-97-CA-50
"
)
.
MAC
(
"
14-75-5B-E3-DE-1F
"
)
.
build
());
.
build
());
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment