Commit 6a33a251 by hy

项目初始化

parents
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store
.idea/
\ No newline at end of file
**生成私钥文件private.ks**
```bash
keytool -genkeypair -dname "CN=TBYF HIP" -alias standard -keystore private.ks -storepass "Esb@123$%^" -validity 3650
```
私钥文件密码: `Esb@123$%^`
**生成公钥文件public.ks**
导出证书
```bash
keytool -exportcert -keystore private.ks -alias standard -storepass "Esb@123$%^" -file digital.cert
```
导入证书
```bash
keytool -importcert -file digital.cert -keystore public.ks -alias standard -storepass "Tbyf@123456"
```
公钥文件密码: `Tbyf@123456`
**迁移jks(java keystore)格式至行业标准格式pkcs12**
```bash
keytool -importkeystore -srckeystore private.ks -destkeystore private.ks -deststoretype pkcs12
```
```bash
keytool -importkeystore -srckeystore public.ks -destkeystore public.ks -deststoretype pkcs12
```
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tbyf.license</groupId>
<artifactId>license-generator</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<truelicense-v4.version>4.0.3</truelicense-v4.version>
</properties>
<dependencies>
<dependency>
<groupId>global.namespace.truelicense</groupId>
<artifactId>truelicense-v4</artifactId>
<version>${truelicense-v4.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.tbyf.license;
import global.namespace.fun.io.bios.BIOS;
import global.namespace.truelicense.api.License;
import global.namespace.truelicense.api.LicenseInitialization;
import global.namespace.truelicense.api.LicenseManagementContext;
import global.namespace.truelicense.api.LicenseManagementException;
import global.namespace.truelicense.api.VendorLicenseManager;
import global.namespace.truelicense.core.passwd.ObfuscatedPasswordProtection;
import global.namespace.truelicense.obfuscate.ObfuscatedString;
import global.namespace.truelicense.v4.V4;
import javax.security.auth.x500.X500Principal;
public class LicenseManager {
private static final String SUBJECT = "HIP";
private static final String DISTINGUISHED_NAME = "CN=TBYF HIP";
private static final String KEY_STORE_FILE = "private.ks";
static LicenseInitialization licenseInitialization;
private static final LicenseManagementContext _managementContext = V4
.builder()
.initialization(license -> {
license.setIssuer(new X500Principal(DISTINGUISHED_NAME));
})
.subject(SUBJECT)
.build();
volatile VendorLicenseManager _manager;
public VendorLicenseManager manager() {
VendorLicenseManager m = this._manager;
return null != m ? m : (this._manager = newManager());
}
private VendorLicenseManager newManager() {
return _managementContext
.vendor()
.encryption()
.protection(protection(new long[]{0xa62021d62ef7e061L, 0xd32b4d88c40291afL})) /* "P@ssw0rd" */
.up()
.authentication()
.alias("standard")
.loadFromResource(KEY_STORE_FILE)
.storeProtection(protection(new long[]{0x1bc1838eb8e7378cL, 0x88679932d1e8bedcL, 0x6e59d724487b1939L})) /* "Esb@123$%^" */
.up()
.build();
}
private static ObfuscatedPasswordProtection protection(long[] longs) {
return new ObfuscatedPasswordProtection(new ObfuscatedString(longs));
}
public void generate(String file) throws LicenseManagementException {
VendorLicenseManager manager = manager();
License license = manager.parameters().licenseFactory().license();
license.setExtra("2333");
manager.generateKeyFrom(license)
.saveTo(BIOS.file(file));
}
}
package com.tbyf.license;
import global.namespace.truelicense.api.LicenseManagementException;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class LicenseManagerTest {
@Test
void generate() throws LicenseManagementException {
new LicenseManager().generate("hip.lic");
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment