get RSA Public Key By Specification - Java Security

Java examples for Security:RSA

Description

get RSA Public Key By Specification

Demo Code


//package com.java2s;

import java.security.KeyFactory;

import java.security.NoSuchAlgorithmException;

import java.security.PublicKey;

import java.security.spec.InvalidKeySpecException;

import java.security.spec.RSAPublicKeySpec;

public class Main {
    public static PublicKey getPubKeyBySpec(RSAPublicKeySpec spec) {
        try {//from   w ww .  j av a2s .  c om
            KeyFactory keyFactory = KeyFactory.getInstance("RSA");
            return keyFactory.generatePublic(spec);
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        } catch (InvalidKeySpecException e) {
            throw new RuntimeException(e);
        }
    }
}

Related Tutorials