All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.icthh.xm.commons.security.oauth2.JwtVerificationKeyClient Maven / Gradle / Ivy

There is a newer version: 4.0.17
Show newest version
package com.icthh.xm.commons.security.oauth2;

import lombok.SneakyThrows;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.security.PublicKey;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;

public interface JwtVerificationKeyClient {

    byte[] fetchKeyContent();

    @SneakyThrows
    default PublicKey getVerificationKey() {
        byte[] content = fetchKeyContent();
        if (content == null) {
            return null;
        }

        CertificateFactory f = CertificateFactory.getInstance("X.509");
        X509Certificate certificate = (X509Certificate) f.generateCertificate(new ByteArrayInputStream(content));
        return certificate.getPublicKey();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy