Skip to content

Commit c0e3889

Browse files
author
zihluwang
committed
Merge remote-tracking branch 'origin/release/v2.0.0' into release/v2.0.0
2 parents 526ebd1 + d535bd1 commit c0e3889

File tree

8 files changed

+75
-195
lines changed

8 files changed

+75
-195
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# JDevKit
22

3+
![Static Badge](https://img.shields.io/badge/tag-v2.0.0-orange)
4+
![Static Badge](https://img.shields.io/badge/maven_central-v2.0.0-orange)
5+
![Static Badge](https://img.shields.io/badge/licence-Apache_2.0-green)
6+
![Static Badge](https://img.shields.io/badge/JDK-%E2%89%A517-blue)
7+
8+
39
JDevKit is a Java Development Kit that offers a set of convenient tools for writing code efficiently.
410

511
## Installation and Usage

devkit-core/README.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,4 @@
22

33
## Introduction
44

5-
This module is the main part of `JDevKit`, an open-source Java class library that provides a set of convenient tools to streamline code development and enhance productivity. This module serves as the basement of other modules.
6-
7-
## Prerequisites
8-
9-
This whole `JDevKit` is developed by **JDK 17**, which means you have to use JDK 17 for better experience.
10-
11-
## Installation
12-
13-
You don't have to install this module at all, any module which is from `JDevKit` contains this `devkit-core` module.
5+
This module serves as the basement of `JDevKit`. It provides some base exceptions that `JDevKit` might use.

devkit-utils/README.md

Lines changed: 9 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,15 @@
22

33
## Introduction
44

5-
This module is part of `JDevKit`, an open-source Java Development Kit that provides a set of
6-
convenient tools to streamline code development and enhance productivity. This module serves as the
7-
useful toolkit for the library, contains a collection of utility classes commonly used in all Java
8-
Application development.
5+
This module provides a set of utilities to streamline Java codes.
96

10-
## Prerequisites
7+
## Features
118

12-
This whole `JDevKit` is developed by **JDK 17**, which means you have to use JDK 17 for
13-
better experience.
9+
- AES encryption and decryption;
10+
- Base64 encode and decode;
11+
- Boolean calculation;
12+
- Reduce `if...else...` with **lambdas**;
13+
- Hash calculation for strings;
14+
- Convert Java beans to map and map to Java beans;
15+
- Simplified range generator.
1416

15-
## Installation
16-
17-
### If you are using `Maven`
18-
19-
It is quite simple to install this module by `Maven`. The only thing you need to do is find your
20-
`pom.xml` file in the project, then find the `<dependencies>` node in the `<project>` node, and add
21-
the following codes to `<dependencies>` node:
22-
23-
```xml
24-
<dependency>
25-
<groupId>com.onixbyte</groupId>
26-
<artifactId>devkit-utils</artifactId>
27-
<version>${devkit-utils.version}</version>
28-
</dependency>
29-
```
30-
31-
And run `mvn dependency:get` in your project root folder(i.e., if your `pom.xml` is located at
32-
`/path/to/your/project/pom.xml`, then your current work folder should be `/path/to/your/project`),
33-
then `Maven` will automatically download the `jar` archive from `Maven Central Repository`. This
34-
could be **MUCH EASIER** if you are using IDE(i.e., IntelliJ IDEA), the only thing you need to do
35-
is click the refresh button of `Maven`.
36-
37-
If you are restricted using the Internet, and have to make `Maven` offline, you could follow the
38-
following steps.
39-
40-
1. Download the `jar` file from any place you can get and transfer the `jar` files to your
41-
work computer.
42-
2. Move the `jar` files to your local `Maven` Repository as the path of
43-
`/path/to/maven_local_repo/com/onixbyte/devkit-utils/`.
44-
45-
### If you are using `Gradle`
46-
47-
Add this module to your project with `Gradle` is much easier than doing so with `Maven`.
48-
49-
Find `build.gradle` in the needed project, and add the following code to the `dependencies` closure
50-
in the build script:
51-
52-
```groovy
53-
implementation 'com.onixbyte:devkit-utils:${devkit-utils.version}'
54-
```

guid/README.md

Lines changed: 26 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2,68 +2,37 @@
22

33
## Introduction
44

5-
Module `guid` is a library that provides utilities for generating and working with globally unique
6-
identifiers (GUIDs). GUIDs are globally unique across all devices and systems, making them ideal
7-
for various use cases like database record keys, distributed systems, and tracking objects.
5+
Module `guid` serves as a guid creator for other `JDevKit` modules. You can also use this module as a guid creator standards.
86

9-
The `guid` module offers a reliable and efficient GUID generator, allowing developers to create
10-
unique identifiers with low collision probability. It also provides features to customize the
11-
format of generated GUIDs, making it flexible and suitable for different applications.
7+
We have already implemented `SnowflakeGuidCreator`, you can also implement a custom guid creations by implementing `com.onixbyte.guid.GuidCreator`.
128

13-
With `guid`, developers can easily integrate globally unique identifiers into their projects,
14-
ensuring data integrity, avoiding duplicates, and simplifying the identification of objects across
15-
various systems. The module is designed to be simple to use, highly performant, and compatible with
16-
different programming languages and frameworks.
9+
## Example usage
1710

18-
## Prerequisites
11+
### A UUID creator
1912

20-
This whole `JDevKit` is developed by **JDK 17**, which means you have to use JDK 17 for
21-
better experience.
22-
23-
## Installation
24-
25-
### If you are using `Maven`
26-
27-
It is quite simple to install this module by `Maven`. The only thing you need to do is find your
28-
`pom.xml` file in the project, then find the `<dependencies>` node in the `<project>` node, and add
29-
the following codes to `<dependencies>` node:
30-
31-
```xml
32-
<dependency>
33-
<groupId>com.onixbyte</groupId>
34-
<artifactId>devkit-utils</artifactId>
35-
<version>${devkit-utils.version}</version>
36-
</dependency>
13+
```java
14+
GuidCreator<UUID> uuidCreator = (GuidCreator<UUID>) UUID::randomUUID;
3715
```
3816

39-
And run `mvn dependency:get` in your project root folder(i.e., if your `pom.xml` is located at
40-
`/path/to/your/project/pom.xml`, then your current work folder should be `/path/to/your/project`),
41-
then `Maven` will automatically download the `jar` archive from `Maven Central Repository`. This
42-
could be **MUCH EASIER** if you are using IDE(i.e., IntelliJ IDEA), the only thing you need to do
43-
is click the refresh button of `Maven`.
44-
45-
If you are restricted using the Internet, and have to make `Maven` offline, you could follow the
46-
following steps.
47-
48-
1. Download the `jar` file from any place you can get and transfer the `jar` files to your work
49-
computer.
50-
2. Move the `jar` files to your local `Maven` Repository as the path of
51-
`/path/to/maven_local_repo/com/onixbyte/devkit-utils/`.
52-
53-
### If you are using `Gradle`
54-
55-
Add this module to your project with `Gradle` is much easier than doing so with `Maven`.
56-
57-
Find `build.gradle` in the needed project, and add the following code to the `dependencies` closure
58-
in the build script:
59-
60-
```groovy
61-
implementation 'com.onixbyte:guid:${guid.version}'
17+
### A custom guid creator
18+
19+
Assume that you need serial guid creator.
20+
21+
```java
22+
@Component
23+
public class CustomGuidCreator implementes GuidCreator<String> {
24+
25+
public final RedisTemplate<String, Long> serialRedisTemplate;
26+
27+
@Autowired
28+
public CustomGuidCreator(RedisTemplate<String, Long> serialRedisTemplate) {
29+
this.serialRedisTemplate = serialRedisTemplate;
30+
}
31+
32+
@Override public String nextId() {
33+
return "SOME_PREFIX" + serialRedisTemplate.opsForValue().get("some_serial_key");
34+
}
35+
36+
}
6237
```
6338

64-
### If you are not using `Maven` or `Gradle`
65-
66-
1. Download the `jar` file from the Internet.
67-
2. Create a folder in your project and name it as a name you like(i.e., for me, I prefer `vendor`).
68-
3. Put the `jar` file to the folder you just created in Step 2.
69-
4. Add this folder to your project `classpath`.

key-pair-loader/src/main/java/com/onixbyte/security/impl/EcKeyLoader.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,15 @@ public class EcKeyLoader implements KeyLoader {
5757

5858
private final KeyFactory keyFactory;
5959

60+
private final Base64.Decoder decoder;
61+
6062
/**
6163
* Initialise a key loader for EC-based algorithms.
6264
*/
6365
public EcKeyLoader() {
6466
try {
6567
this.keyFactory = KeyFactory.getInstance("EC");
68+
this.decoder = Base64.getDecoder();
6669
} catch (NoSuchAlgorithmException e) {
6770
throw new KeyLoadingException(e);
6871
}
@@ -84,7 +87,7 @@ public ECPrivateKey loadPrivateKey(String pemKeyText) {
8487
.replaceAll("-----BEGIN (EC )?PRIVATE KEY-----", "")
8588
.replaceAll("-----END (EC )?PRIVATE KEY-----", "")
8689
.replaceAll("\n", "");
87-
var decodedKeyString = Base64.getDecoder().decode(pemKeyText);
90+
var decodedKeyString = decoder.decode(pemKeyText);
8891
var keySpec = new PKCS8EncodedKeySpec(decodedKeyString);
8992

9093
var _key = keyFactory.generatePrivate(keySpec);
@@ -114,7 +117,7 @@ public ECPublicKey loadPublicKey(String pemKeyText) {
114117
.replaceAll("-----BEGIN (EC )?PUBLIC KEY-----", "")
115118
.replaceAll("-----END (EC )?PUBLIC KEY-----", "")
116119
.replaceAll("\n", "");
117-
var keyBytes = Base64.getDecoder().decode(pemKeyText);
120+
var keyBytes = decoder.decode(pemKeyText);
118121
var spec = new X509EncodedKeySpec(keyBytes);
119122
var key = keyFactory.generatePublic(spec);
120123
if (key instanceof ECPublicKey publicKey) {

map-util-unsafe/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Map Util Unsafe
2+
3+
`map-util-unsafe` provides a set of more convenient utilities for converting Java bean to Map or Map to Java bean, but which are less safe than the `MapUtil` provided in `devkit-utils`.
4+
5+
This `MapUtil` is implemented with Reflect API, which might be removed in later JDKs.

num4j/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Num4j
2+
3+
`num4j` provides some mathematical algorithms and utilities such as chained high-precision mathematical calculator and percentile statistic algorithm.
Lines changed: 20 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,37 @@
11
# Property Guard
22

3-
## Introduction
3+
`property-guard-spring-boot-starter` is a utility that can help you protect secret values in Spring Boot configurations.
44

5-
This feature is designed to protect the security of configurations and data, to a certain extent, to control the flow of developers leading to the leakage of sensitive information.
5+
## Example usage
66

7-
## Prerequisites
7+
### 1. Implementation this module
88

9-
This whole `JDevKit` is developed by **JDK 17**, which means you have to use JDK 17 for better experience. Except this, this module is designed for Spring Boot framework, so you have to install Spring Boot (v3) in your application.
10-
11-
## Installation
12-
13-
### If you are using `Maven`
14-
15-
It is quite simple to install this module by `Maven`. The only thing you need to do is find your `pom.xml` file in the project, then find the `<dependencies>` node in the `<project>` node, and add the following codes to `<dependencies>` node:
16-
17-
```xml
18-
<dependency>
19-
<groupId>cn.org.codecrafters</groupId>
20-
<artifactId>property-guard-spring-boot-starter</artifactId>
21-
<version>${property-guard-spring-boot-starter.version}</version>
22-
</dependency>
23-
```
24-
25-
And run `mvn dependency:get` in your project root folder(i.e., if your `pom.xml` is located at `/path/to/your/project/pom.xml`, then your current work folder should be `/path/to/your/project`), then `Maven` will automatically download the `jar` archive from `Maven Central Repository`. This could be **MUCH EASIER** if you are using IDE(i.e., IntelliJ IDEA), the only thing you need to do is click the refresh button of `Maven`.
26-
27-
If you are restricted using the Internet, and have to make `Maven` offline, you could follow the following steps.
28-
29-
1. Download the `jar` file from any place you can get and transfer the `jar` files to your work computer.
30-
2. Move the `jar` files to your local `Maven` Repository as the path of `/path/to/maven_local_repo/cn/org/codecrafters/property-guard-spring-boot-starter/`.
31-
32-
### If you are using `Gradle`
33-
34-
Add this module to your project with `Gradle` is much easier than doing so with `Maven`.
35-
36-
Find `build.gradle` in the needed project, and add the following code to the `dependencies` closure in the build script:
37-
38-
```groovy
39-
implementation 'cn.org.codecrafters:property-guard-spring-boot-starter:${property-guard-spring-boot-starter.version}'
40-
```
41-
42-
### If you are not using `Maven` or `Gradle`
43-
44-
1. Download the `jar` file from the Internet.
45-
2. Create a folder in your project and name it as a name you like(i.e., for me, I prefer `vendor`).
46-
3. Put the `jar` file to the folder you just created in Step 2.
47-
4. Add this folder to your project `classpath`.
48-
49-
## Usage
50-
51-
First, you need a 16-bit-long secret. If you don't have a good way to get a secret, you could consider using our `utils.com.onixbyte.devkit.AesUtil` or `com.onixbyte.simplejwt.SecretCreator` to create a secret.
52-
53-
For example:
54-
```java
55-
import utils.com.onixbyte.devkit.AesUtil;
56-
import com.onixbyte.simplejwt.SecretCreator;
57-
58-
class GenerateRandomKeySample {
59-
public static void main(String[] args) {
60-
var secret1 = AesUtil.generateRandomSecret();
61-
var secret2 = SecretCreator.createSecret(16, true, true, true);
62-
}
9+
```kotlin
10+
dependencies {
11+
implementation(platform("com.onixbyte:devkit-bom:$devKitVersion"))
12+
implementation("com.onixbyte:devkit-utils")
13+
implementation("com.onixbyte:property-guard-spring-boot-starter")
6314
}
6415
```
6516

66-
Then, remember this secret and encrypt the configuration properties that are required high security. For example:
17+
### 2. Generate a secret
6718

68-
```java
69-
import utils.com.onixbyte.devkit.AesUtil;
19+
Use the following codes to get a random secret.
7020

71-
class EncryptSample {
72-
public static void main(String[] args) {
73-
var dataNeedEncryption = "Sample Value";
74-
var key = "3856faef0d2d4f33";
75-
var encryptedData = AesUtil.encrypt(dataNeedEncryption, key);
21+
```java
22+
@SpringBootTest
23+
class SpringBootApplicationTest {
24+
25+
@Test
26+
void contextLoads() {
27+
System.out.println(AesUtil.generateRandomSecret()); // Output: a 16-char long secret
7628
}
7729
}
7830
```
7931

80-
After that, copy the encrypted data to `application.properties` or `application.yml`.
81-
82-
For `yml`:
83-
```yaml
84-
app:
85-
sample-configuration: pe:t4YBfv8M9ZmTzWgTi2gJqg== # "pe:" is the prefix that declare that this property is encrypted.
86-
```
87-
88-
For `properties`:
89-
```properties
90-
app.sample-configuration=pe:t4YBfv8M9ZmTzWgTi2gJqg==
91-
```
32+
Or you can write a 16-char long secret by yourself.
9233

93-
## Contact
34+
### 3. Encrypt your secret properties and place them into your configuration file
9435

95-
If you have any suggestions, ideas, don't hesitate contacting us via [GitHub Issues](https://github.com/CodeCraftersCN/jdevkit/issues/new) or [Discord Community](https://discord.gg/NQK9tjcBB8).
36+
### 4. Run application with parameter `--pg.key=$your_secret`
9637

97-
If you face any bugs while using our library and you are able to fix any bugs in our library, we would be happy to accept pull requests from you on [GitHub](https://github.com/CodeCraftersCN/jdevkit/compare).

0 commit comments

Comments
 (0)