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 7464a9d..d8806a0 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 @@ -68,6 +68,19 @@ public interface KeyLoader { throw new KeyLoadingException("This key loader does not support loading an RSA public key."); } + /** + * Loads an EC public key using the provided x and y coordinates together with the curve name. + *
+ * 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."); } diff --git a/key-pair-loader/src/main/java/com/onixbyte/security/impl/ECKeyLoader.java b/key-pair-loader/src/main/java/com/onixbyte/security/impl/ECKeyLoader.java index ffc45ef..e482c0f 100644 --- a/key-pair-loader/src/main/java/com/onixbyte/security/impl/ECKeyLoader.java +++ b/key-pair-loader/src/main/java/com/onixbyte/security/impl/ECKeyLoader.java @@ -131,6 +131,23 @@ public class ECKeyLoader implements KeyLoader { } } + /** + * Loads an EC public key from the given hexadecimal x and y coordinates alongside the curve name. + *
+ * This method converts the hexadecimal string representations of the EC point coordinates into {@link BigInteger} + * instances, then constructs an {@link ECPoint} and retrieves the corresponding {@link ECParameterSpec} for the + * named curve. Subsequently, it utilises the {@link KeyFactory} to generate an {@link ECPublicKey}. + *
+ * Only curves listed in {@link #SUPPORTED_CURVES} are supported. Should the specified curve name be unsupported, + * or if key construction fails due to invalid parameters or unsupported algorithms, a {@link KeyLoadingException} + * will be thrown. + * + * @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 {@link ECPublicKey} generated from the specified coordinates and curve + * @throws KeyLoadingException if the curve is unsupported or key generation fails + */ @Override public ECPublicKey loadPublicKey(String xHex, String yHex, String curveName) { if (!SUPPORTED_CURVES.contains(curveName)) {