docs: add docs for loading RSA public key with modulus and exponent

This commit is contained in:
siujamo
2025-06-09 11:52:12 +08:00
parent e03cc180c9
commit a4d42722ad
2 changed files with 21 additions and 4 deletions
@@ -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.");
}
@@ -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 {