Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ tasks.test {

publishing {
publications {
create<MavenPublication>("devkitUtils") {
create<MavenPublication>("commonToolbox") {
groupId = group.toString()
artifactId = "devkit-utils"
artifactId = "common-toolbox"
version = artefactVersion

pom {
name = "OnixByte Common Toolbox"
description = "The utils module of JDevKit."
description = "The utils module of OnixByte toolbox."
url = projectUrl

licenses {
Expand All @@ -82,8 +82,8 @@ publishing {
}

scm {
connection = "scm:git:git://github.com:onixbyte/onixbyte-toolbox.git"
developerConnection = "scm:git:git://github.com:onixbyte/onixbyte-toolbox.git"
connection = "scm:git:git://github.com:OnixByte/JDevKit.git"
developerConnection = "scm:git:git://github.com:OnixByte/JDevKit.git"
url = projectGithubUrl
}

Expand All @@ -107,7 +107,7 @@ publishing {
from(components["java"])

signing {
sign(publishing.publications["devkitUtils"])
sign(publishing.publications["commonToolbox"])
}
}

Expand All @@ -122,4 +122,4 @@ publishing {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package com.onixbyte.devkit.utils;
package com.onixbyte.common.util;

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package com.onixbyte.devkit.utils;
package com.onixbyte.common.util;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -209,4 +209,4 @@ public static String decodeUrlComponents(String value) {

private static Base64.Decoder urlDecoder;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package com.onixbyte.devkit.utils;
package com.onixbyte.common.util;

import java.util.Arrays;
import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package com.onixbyte.devkit.utils;
package com.onixbyte.common.util;

import java.util.Objects;
import java.util.function.BooleanSupplier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package com.onixbyte.devkit.utils;
package com.onixbyte.common.util;

import java.util.ArrayList;
import java.util.Collection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package com.onixbyte.devkit.utils;
package com.onixbyte.common.util;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package com.onixbyte.devkit.utils;
package com.onixbyte.common.util;

import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package com.onixbyte.devkit.utils;
package com.onixbyte.common.util;

import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package com.onixbyte.devkit.utils;
package com.onixbyte.common.util;

import java.util.stream.IntStream;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package com.onixbyte.devkit.utils;
package com.onixbyte.common.util;

import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package com.onixbyte.devkit.utils;
package com.onixbyte.common.util;

import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package com.onixbyte.devkit.utils;
package com.onixbyte.common.util;

import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package com.onixbyte.devkit.utils;
package com.onixbyte.common.util;

import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package com.onixbyte.devkit.utils;
package com.onixbyte.common.util;

import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package com.onixbyte.devkit.utils;
package com.onixbyte.common.util;

import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package com.onixbyte.devkit.utils;
package com.onixbyte.common.util;

import org.junit.jupiter.api.Test;

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ tasks.test {

publishing {
publications {
create<MavenPublication>("keyPairLoader") {
create<MavenPublication>("cryptoToolbox") {
groupId = group.toString()
artifactId = "key-pair-loader"
artifactId = "crypto-toolbox"
version = artefactVersion

pom {
Expand All @@ -87,8 +87,8 @@ publishing {
}

scm {
connection = "scm:git:git://github.com:onixbyte/onixbyte-toolbox.git"
developerConnection = "scm:git:git://github.com:onixbyte/onixbyte-toolbox.git"
connection = "scm:git:git://github.com:OnixByte/JDevKit.git"
developerConnection = "scm:git:git://github.com:OnixByte/JDevKit.git"
url = projectGithubUrl
}

Expand All @@ -112,7 +112,7 @@ publishing {
from(components["java"])

signing {
sign(publishing.publications["keyPairLoader"])
sign(publishing.publications["cryptoToolbox"])
}
}

Expand All @@ -127,4 +127,4 @@ publishing {
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (C) 2024-2025 OnixByte.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.onixbyte.crypto;

import java.security.PrivateKey;

/**
* The {@code PrivateKeyLoader} interface provides utility methods for loading keys pairs from
* PEM-formatted key text. This class supports loading both private and public keys.
*
* @author zihluwang
* @author siujamo
* @version 2.0.0
* @since 1.6.0
*/
public interface PrivateKeyLoader {

/**
* Load private key from pem-formatted key text.
*
* @param pemKeyText pem-formatted key text
* @return loaded private key
*/
PrivateKey loadPrivateKey(String pemKeyText);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (C) 2024-2025 OnixByte.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.onixbyte.crypto;

import com.onixbyte.crypto.exception.KeyLoadingException;

import java.security.PublicKey;
import java.security.interfaces.ECPublicKey;
import java.security.interfaces.RSAPublicKey;

/**
*
* @author siujamo
* @version 3.0.0
*/
public interface PublicKeyLoader {

/**
* Load public key from pem-formatted key text.
*
* @param pemKeyText pem-formatted key text
* @return loaded private key
*/
PublicKey loadPublicKey(String pemKeyText);

/**
* Loads an EC public key using the provided x and y coordinates together with the curve name.
* <p>
* This default implementation throws a {@link KeyLoadingException} to signify that this key
* loader does not support loading an EC public key. Implementing classes are expected to
* override this method to supply their own loading logic.
*
* @param xHex the hexadecimal string representing the x coordinate of the EC point
* @param yHex the hexadecimal string representing the y coordinate of the EC point
* @param curveName the name of the elliptic curve
* @return the loaded {@link ECPublicKey} instance
* @throws KeyLoadingException if loading is not supported or fails
*/
default ECPublicKey loadPublicKey(String xHex, String yHex, String curveName) {
throw new KeyLoadingException("This key loader does not support loading an EC public key.");
}

/**
* Loads an RSA public key using the provided modulus and exponent.
* <p>
* This default implementation throws a {@link KeyLoadingException} to signify that this key
* loader does not support loading an RSA public key. Implementing classes are expected to
* override this method to supply their own loading logic.
*
* @param modulus the modulus value of the RSA public key, usually represented in hexadecimal
* or Base64 string format
* @param exponent the public exponent value of the RSA public key, usually represented in
* hexadecimal or Base64 string format
* @return the loaded {@link RSAPublicKey} instance
* @throws KeyLoadingException if loading is not supported or fails
*/
default RSAPublicKey loadPublicKey(String modulus, String exponent) {
throw new KeyLoadingException("This key loader does not support loading an RSA public key.");
}
}
Loading