Java Key Public getPublicKeySpec(KeyPair kp)

Here you can find the source of getPublicKeySpec(KeyPair kp)

Description

get Public Key Spec

License

Open Source License

Declaration

public static RSAPublicKeySpec getPublicKeySpec(KeyPair kp)
            throws NoSuchAlgorithmException, InvalidKeySpecException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.security.KeyFactory;
import java.security.KeyPair;

import java.security.NoSuchAlgorithmException;

import java.security.PublicKey;

import java.security.spec.InvalidKeySpecException;

import java.security.spec.RSAPublicKeySpec;

public class Main {
    public static RSAPublicKeySpec getPublicKeySpec(KeyPair kp)
            throws NoSuchAlgorithmException, InvalidKeySpecException {
        KeyFactory fact = KeyFactory.getInstance("RSA");
        RSAPublicKeySpec pub = fact.getKeySpec(kp.getPublic(), RSAPublicKeySpec.class);
        return pub;
    }/*  w  w  w.  j  a  va  2  s. c o m*/

    public static RSAPublicKeySpec getPublicKeySpec(PublicKey pubkey)
            throws NoSuchAlgorithmException, InvalidKeySpecException {
        KeyFactory fact = KeyFactory.getInstance("RSA");
        RSAPublicKeySpec pub = fact.getKeySpec(pubkey, RSAPublicKeySpec.class);
        return pub;
    }
}

Related

  1. getPublicKeyFromBytes(final String algorithm, final byte[] publicKeyBytes)
  2. getPublicKeyFromFile(File cert, String alias, String password)
  3. getPublicKeyFromPEMFile(String fileName, String jceProvider)
  4. getPublicKeyFromString(String certificateString)
  5. getPublicKeyModulus(RSAPublicKey publicKey)
  6. getPublicPutMethodForResultClass(final Class resultClass)