Java Key Public getPublicKeyFromFile(File cert, String alias, String password)

Here you can find the source of getPublicKeyFromFile(File cert, String alias, String password)

Description

get Public Key From File

License

Open Source License

Declaration

public static PublicKey getPublicKeyFromFile(File cert, String alias,
        String password) throws Exception 

Method Source Code

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

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import java.security.Key;
import java.security.KeyStore;

import java.security.PublicKey;

import java.security.cert.Certificate;

public class Main {

    public static PublicKey getPublicKeyFromFile(File cert, String alias,
            String password) throws Exception {
        KeyStore ks = KeyStore.getInstance("JKS");
        char[] pwd = password.toCharArray();
        InputStream is = new FileInputStream(cert);
        ks.load(is, pwd);// w w w.  j  ava2  s.  c o m
        Key key = ks.getKey(alias, pwd);
        Certificate c = ks.getCertificate(alias);
        PublicKey p = c.getPublicKey();
        return p;
    }
}

Related

  1. getPublicKey(String modulus, String exponent)
  2. getPublicKey(String publicKeyContents)
  3. getPublicKey(String publicKeyFile)
  4. getPublicKey(String publicKeyFilepath, String algorithm)
  5. getPublicKeyFromBytes(final String algorithm, final byte[] publicKeyBytes)
  6. getPublicKeyFromPEMFile(String fileName, String jceProvider)
  7. getPublicKeyFromString(String certificateString)
  8. getPublicKeyModulus(RSAPublicKey publicKey)
  9. getPublicKeySpec(KeyPair kp)