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
9cea664d
Commit
9cea664d
authored
Jan 11, 2024
by
hy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
6a33a251
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
65 additions
and
4 deletions
+65
-4
pom.xml
pom.xml
+7
-0
LicenseManager.java
src/main/java/com/tbyf/license/LicenseManager.java
+6
-3
LicenseParams.java
src/main/java/com/tbyf/license/LicenseParams.java
+41
-0
digital.cert
src/main/resources/digital.cert
+0
-0
LicenseManagerTest.java
src/test/java/com/tbyf/license/LicenseManagerTest.java
+11
-1
No files found.
pom.xml
View file @
9cea664d
...
...
@@ -28,5 +28,11 @@
<version>
5.10.0
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
<version>
1.18.28
</version>
<optional>
true
</optional>
</dependency>
</dependencies>
</project>
\ No newline at end of file
src/main/java/com/tbyf/license/LicenseManager.java
View file @
9cea664d
...
...
@@ -23,6 +23,7 @@ public class LicenseManager {
private
static
final
LicenseManagementContext
_managementContext
=
V4
.
builder
()
.
initialization
(
license
->
{
license
.
setSubject
(
SUBJECT
);
license
.
setIssuer
(
new
X500Principal
(
DISTINGUISHED_NAME
));
})
.
subject
(
SUBJECT
)
...
...
@@ -54,12 +55,14 @@ public class LicenseManager {
return
new
ObfuscatedPasswordProtection
(
new
ObfuscatedString
(
longs
));
}
public
void
generate
(
String
file
)
throws
LicenseManagementException
{
public
void
generate
(
LicenseParams
params
)
throws
LicenseManagementException
{
VendorLicenseManager
manager
=
manager
();
License
license
=
manager
.
parameters
().
licenseFactory
().
license
();
license
.
setExtra
(
"2333"
);
license
.
setNotBefore
(
params
.
getStartDate
());
license
.
setNotAfter
(
params
.
getExpirationDate
());
license
.
setExtra
(
params
.
getMAC
());
manager
.
generateKeyFrom
(
license
)
.
saveTo
(
BIOS
.
file
(
file
));
.
saveTo
(
BIOS
.
file
(
params
.
getFilename
()
));
}
}
src/main/java/com/tbyf/license/LicenseParams.java
0 → 100644
View file @
9cea664d
package
com
.
tbyf
.
license
;
import
lombok.Builder
;
import
lombok.Getter
;
import
java.util.Calendar
;
import
java.util.Date
;
@Builder
public
class
LicenseParams
{
@Getter
private
String
filename
;
private
Date
startDate
;
// 有效天数
private
int
validity
;
private
Date
expirationDate
;
@Getter
private
String
MAC
;
// MAC硬件地址
public
Date
getExpirationDate
()
{
Date
ed
=
this
.
expirationDate
;
return
null
!=
ed
?
ed
:
calculateExpirationDate
();
}
public
Date
getStartDate
()
{
Date
sd
=
this
.
startDate
;
return
null
!=
sd
?
sd
:
new
Date
();
}
private
Date
calculateExpirationDate
()
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
getStartDate
());
calendar
.
add
(
Calendar
.
DAY_OF_YEAR
,
this
.
validity
);
return
calendar
.
getTime
();
}
}
src/main/resources/digital.cert
deleted
100644 → 0
View file @
6a33a251
File deleted
src/test/java/com/tbyf/license/LicenseManagerTest.java
View file @
9cea664d
...
...
@@ -3,12 +3,21 @@ package com.tbyf.license;
import
global.namespace.truelicense.api.LicenseManagementException
;
import
org.junit.jupiter.api.Test
;
import
java.util.Date
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
class
LicenseManagerTest
{
@Test
void
generate
()
throws
LicenseManagementException
{
new
LicenseManager
().
generate
(
"hip.lic"
);
new
LicenseManager
()
.
generate
(
LicenseParams
.
builder
()
.
filename
(
"hip.lic"
)
.
startDate
(
new
Date
())
.
validity
(
5
)
.
MAC
(
"CC-F9-E4-97-CA-48"
)
.
build
());
}
}
\ No newline at end of file
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