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

bluecrystal.service.jwt.CredentialPKey Maven / Gradle / Ivy

There is a newer version: 1.16.0
Show newest version
package bluecrystal.service.jwt;

import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.X509EncodedKeySpec;

import org.bouncycastle.util.encoders.Base64;

public class CredentialPKey implements Credential {
    private PrivateKey privateKey;
    private PublicKey publicKey;

	public CredentialPKey(PrivateKey privateKey, PublicKey publicKey) {
		super();
		this.privateKey = privateKey;
		this.publicKey = publicKey;
	}
	
	public CredentialPKey(String publicKey) throws InvalidKeySpecException, NoSuchAlgorithmException {
		super();

		byte[] pkBytes = Base64.decode(publicKey);
		this.privateKey = null;
		this.publicKey = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(pkBytes));
	}

	public CredentialPKey() {
		super();
		// TODO Auto-generated constructor stub
	}

	@Override
	public AppAlgorithm getAlgorithn() {
		return AppAlgorithm.RS256;
	}

	public PrivateKey getPrivateKey() {
		return privateKey;
	}

	public PublicKey getPublicKey() {
		return publicKey;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy