refactor: renamed key pair loader

This commit is contained in:
siujamo
2025-06-09 11:49:27 +08:00
parent 579a2e2e35
commit 6ac9f1ae49
3 changed files with 6 additions and 8 deletions
@@ -53,7 +53,7 @@ import java.util.Base64;
* @version 2.0.0 * @version 2.0.0
* @since 2.0.0 * @since 2.0.0
*/ */
public class EcKeyLoader implements KeyLoader { public class ECKeyLoader implements KeyLoader {
private final KeyFactory keyFactory; private final KeyFactory keyFactory;
@@ -62,7 +62,7 @@ public class EcKeyLoader implements KeyLoader {
/** /**
* Initialise a key loader for EC-based algorithms. * Initialise a key loader for EC-based algorithms.
*/ */
public EcKeyLoader() { public ECKeyLoader() {
try { try {
this.keyFactory = KeyFactory.getInstance("EC"); this.keyFactory = KeyFactory.getInstance("EC");
this.decoder = Base64.getDecoder(); this.decoder = Base64.getDecoder();
@@ -44,7 +44,7 @@ import java.util.Base64;
* @see KeyLoader * @see KeyLoader
* @see KeyLoadingException * @see KeyLoadingException
*/ */
public class RsaKeyLoader implements KeyLoader { public class RSAKeyLoader implements KeyLoader {
private final Base64.Decoder decoder; private final Base64.Decoder decoder;
private final KeyFactory keyFactory; private final KeyFactory keyFactory;
@@ -55,7 +55,7 @@ public class RsaKeyLoader implements KeyLoader {
* This constructor initialises the Base64 decoder and the RSA {@link KeyFactory}. It may throw * This constructor initialises the Base64 decoder and the RSA {@link KeyFactory}. It may throw
* a {@link KeyLoadingException} if the RSA algorithm is not available. * a {@link KeyLoadingException} if the RSA algorithm is not available.
*/ */
public RsaKeyLoader() { public RSAKeyLoader() {
try { try {
this.decoder = Base64.getDecoder(); this.decoder = Base64.getDecoder();
this.keyFactory = KeyFactory.getInstance("RSA"); this.keyFactory = KeyFactory.getInstance("RSA");
@@ -19,8 +19,7 @@ package com.onixbyte.simplejwt.authzero;
import com.onixbyte.devkit.utils.Base64Util; import com.onixbyte.devkit.utils.Base64Util;
import com.onixbyte.guid.GuidCreator; import com.onixbyte.guid.GuidCreator;
import com.onixbyte.security.KeyLoader; import com.onixbyte.security.impl.ECKeyLoader;
import com.onixbyte.security.impl.EcKeyLoader;
import com.onixbyte.simplejwt.TokenPayload; import com.onixbyte.simplejwt.TokenPayload;
import com.onixbyte.simplejwt.TokenResolver; import com.onixbyte.simplejwt.TokenResolver;
import com.onixbyte.simplejwt.annotations.ExcludeFromPayload; import com.onixbyte.simplejwt.annotations.ExcludeFromPayload;
@@ -43,7 +42,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.security.NoSuchAlgorithmException;
import java.security.interfaces.ECPrivateKey; import java.security.interfaces.ECPrivateKey;
import java.security.interfaces.ECPublicKey; import java.security.interfaces.ECPublicKey;
import java.time.Duration; import java.time.Duration;
@@ -179,7 +177,7 @@ public class AuthzeroTokenResolver implements TokenResolver<DecodedJWT> {
* @return the builder instance * @return the builder instance
*/ */
public Builder keyPair(String publicKey, String privateKey) { public Builder keyPair(String publicKey, String privateKey) {
var keyLoader = new EcKeyLoader(); var keyLoader = new ECKeyLoader();
this.publicKey = keyLoader.loadPublicKey(publicKey); this.publicKey = keyLoader.loadPublicKey(publicKey);
this.privateKey = keyLoader.loadPrivateKey(privateKey); this.privateKey = keyLoader.loadPrivateKey(privateKey);
return this; return this;