Skip to content

Commit a4d4272

Browse files
committed
docs: add docs for loading RSA public key with modulus and exponent
1 parent e03cc18 commit a4d4272

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919

2020
import com.onixbyte.security.exception.KeyLoadingException;
2121

22+
import java.security.KeyFactory;
2223
import java.security.PrivateKey;
2324
import java.security.PublicKey;
2425
import java.security.interfaces.RSAPublicKey;
26+
import java.security.spec.KeySpec;
2527

2628
/**
2729
* The {@code KeyLoader} class provides utility methods for loading keys pairs from PEM-formatted
@@ -52,6 +54,15 @@ public interface KeyLoader {
5254
*/
5355
PublicKey loadPublicKey(String pemKeyText);
5456

57+
/**
58+
* Get the public key with given modulus and public exponent.
59+
*
60+
* @param modulus the modulus
61+
* @param exponent the public exponent
62+
* @return generated public key object from the provided key specification
63+
* @see KeyFactory#getInstance(String)
64+
* @see KeyFactory#generatePublic(KeySpec)
65+
*/
5566
default RSAPublicKey loadPublicKey(String modulus, String exponent) {
5667
throw new KeyLoadingException("This key loader does not support RSA Public key loading.");
5768
}

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@
2525
import java.security.NoSuchAlgorithmException;
2626
import java.security.interfaces.RSAPrivateKey;
2727
import java.security.interfaces.RSAPublicKey;
28-
import java.security.spec.InvalidKeySpecException;
29-
import java.security.spec.PKCS8EncodedKeySpec;
30-
import java.security.spec.RSAPublicKeySpec;
31-
import java.security.spec.X509EncodedKeySpec;
28+
import java.security.spec.*;
3229
import java.util.Base64;
3330

3431
/**
@@ -140,6 +137,15 @@ public RSAPublicKey loadPublicKey(String pemKeyText) {
140137
}
141138
}
142139

140+
/**
141+
* Get the public key with given modulus and public exponent.
142+
*
143+
* @param modulus the modulus
144+
* @param exponent the public exponent
145+
* @return generated public key object from the provided key specification
146+
* @see KeyFactory#getInstance(String)
147+
* @see KeyFactory#generatePublic(KeySpec)
148+
*/
143149
@Override
144150
public RSAPublicKey loadPublicKey(String modulus, String exponent) {
145151
try {

0 commit comments

Comments
 (0)