Java Key Public getPublicKey(String key)

Here you can find the source of getPublicKey(String key)

Description

get Public Key

License

Open Source License

Declaration

public static PublicKey getPublicKey(String key) throws Exception 

Method Source Code


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

import sun.misc.BASE64Decoder;

import java.security.*;

import java.security.spec.X509EncodedKeySpec;

public class Main {

    public static PublicKey getPublicKey(String key) throws Exception {
        byte[] keyBytes;
        keyBytes = (new BASE64Decoder()).decodeBuffer(key);
        X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        return keyFactory.generatePublic(keySpec);
    }/*w w w. jav a 2  s  . co  m*/
}

Related

  1. getPublicKey(String certificatePath)
  2. getPublicKey(String certPath)
  3. getPublicKey(String filename)
  4. getPublicKey(String filename)
  5. getPublicKey(String filename)
  6. getPublicKey(String modulus, String exponent)
  7. getPublicKey(String publicKeyContents)
  8. getPublicKey(String publicKeyFile)
  9. getPublicKey(String publicKeyFilepath, String algorithm)