use of com.nexblocks.authguard.service.exceptions.ServiceException in project AuthGuard by AuthGuard.
the class JwtConfigParser method parseEc.
private static Algorithm parseEc(final String algorithmName, final String publicKeyPath, final String privateKeyPath) {
final byte[] publicKey = KeyLoader.readPemKeyFile(publicKeyPath);
final byte[] privateKey = KeyLoader.readPemKeyFile(privateKeyPath);
final KeyPair keyPair = readEcKeys(publicKey, privateKey);
switch(algorithmName) {
case "EC256":
return Algorithm.ECDSA256((ECPublicKey) keyPair.getPublic(), (ECPrivateKey) keyPair.getPrivate());
case "EC512":
return Algorithm.ECDSA512((ECPublicKey) keyPair.getPublic(), (ECPrivateKey) keyPair.getPrivate());
case "EC256K":
return Algorithm.ECDSA256K((ECPublicKey) keyPair.getPublic(), (ECPrivateKey) keyPair.getPrivate());
default:
throw new ServiceException(ErrorCode.UNSUPPORTED_JWT_ALGORITHM, "Unsupported algorithm " + algorithmName);
}
}
use of com.nexblocks.authguard.service.exceptions.ServiceException in project AuthGuard by AuthGuard.
the class JwtConfigParser method parseRsa.
private static Algorithm parseRsa(final String algorithmName, final String publicKeyPath, final String privateKeyPath) {
final byte[] publicKey = KeyLoader.readPemKeyFile(publicKeyPath);
final byte[] privateKey = KeyLoader.readPemKeyFile(privateKeyPath);
final KeyPair keyPair = readRsaKeys(publicKey, privateKey);
switch(algorithmName) {
case "RSA256":
return Algorithm.RSA256((RSAPublicKey) keyPair.getPublic(), (RSAPrivateKey) keyPair.getPrivate());
case "RSA512":
return Algorithm.RSA512((RSAPublicKey) keyPair.getPublic(), (RSAPrivateKey) keyPair.getPrivate());
default:
throw new ServiceException(ErrorCode.UNSUPPORTED_JWT_ALGORITHM, "Unsupported algorithm " + algorithmName);
}
}
Aggregations