From a4d42722ad40e3f85397334f718bc86781b542a5 Mon Sep 17 00:00:00 2001 From: siujamo Date: Mon, 9 Jun 2025 11:52:12 +0800 Subject: [PATCH] docs: add docs for loading RSA public key with modulus and exponent --- .../main/java/com/onixbyte/security/KeyLoader.java | 11 +++++++++++ .../com/onixbyte/security/impl/RSAKeyLoader.java | 14 ++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/key-pair-loader/src/main/java/com/onixbyte/security/KeyLoader.java b/key-pair-loader/src/main/java/com/onixbyte/security/KeyLoader.java index 0c7a4a5..a367ac1 100644 --- a/key-pair-loader/src/main/java/com/onixbyte/security/KeyLoader.java +++ b/key-pair-loader/src/main/java/com/onixbyte/security/KeyLoader.java @@ -19,9 +19,11 @@ package com.onixbyte.security; import com.onixbyte.security.exception.KeyLoadingException; +import java.security.KeyFactory; import java.security.PrivateKey; import java.security.PublicKey; import java.security.interfaces.RSAPublicKey; +import java.security.spec.KeySpec; /** * The {@code KeyLoader} class provides utility methods for loading keys pairs from PEM-formatted @@ -52,6 +54,15 @@ public interface KeyLoader { */ PublicKey loadPublicKey(String pemKeyText); + /** + * Get the public key with given modulus and public exponent. + * + * @param modulus the modulus + * @param exponent the public exponent + * @return generated public key object from the provided key specification + * @see KeyFactory#getInstance(String) + * @see KeyFactory#generatePublic(KeySpec) + */ default RSAPublicKey loadPublicKey(String modulus, String exponent) { throw new KeyLoadingException("This key loader does not support RSA Public key loading."); } diff --git a/key-pair-loader/src/main/java/com/onixbyte/security/impl/RSAKeyLoader.java b/key-pair-loader/src/main/java/com/onixbyte/security/impl/RSAKeyLoader.java index b0f5dc2..3cf9324 100644 --- a/key-pair-loader/src/main/java/com/onixbyte/security/impl/RSAKeyLoader.java +++ b/key-pair-loader/src/main/java/com/onixbyte/security/impl/RSAKeyLoader.java @@ -25,10 +25,7 @@ import java.security.KeyFactory; import java.security.NoSuchAlgorithmException; import java.security.interfaces.RSAPrivateKey; import java.security.interfaces.RSAPublicKey; -import java.security.spec.InvalidKeySpecException; -import java.security.spec.PKCS8EncodedKeySpec; -import java.security.spec.RSAPublicKeySpec; -import java.security.spec.X509EncodedKeySpec; +import java.security.spec.*; import java.util.Base64; /** @@ -140,6 +137,15 @@ public class RSAKeyLoader implements KeyLoader { } } + /** + * Get the public key with given modulus and public exponent. + * + * @param modulus the modulus + * @param exponent the public exponent + * @return generated public key object from the provided key specification + * @see KeyFactory#getInstance(String) + * @see KeyFactory#generatePublic(KeySpec) + */ @Override public RSAPublicKey loadPublicKey(String modulus, String exponent) { try {