Java Key Public getPublicKey(KeyStore keyStore, String alias, char[] password)

Here you can find the source of getPublicKey(KeyStore keyStore, String alias, char[] password)

Description

get Public Key

License

Open Source License

Declaration

public static PublicKey getPublicKey(KeyStore keyStore, String alias, char[] password)
            throws GeneralSecurityException 

Method Source Code

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

import java.security.GeneralSecurityException;
import java.security.Key;

import java.security.KeyStore;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.cert.Certificate;

public class Main {
    public static PublicKey getPublicKey(KeyStore keyStore, String alias, char[] password)
            throws GeneralSecurityException {
        PublicKey publicKey = null;

        // Get private key
        Key key = keyStore.getKey(alias, password);
        if (key instanceof PrivateKey) {
            // Get certificate of public key
            Certificate cert = keyStore.getCertificate(alias);

            // Get public key
            publicKey = cert.getPublicKey();
        }/*from  w  ww  .j  a  v a  2s .c  o  m*/
        // if alias is a certificate alias, get the public key from the
        // certificate.
        if (publicKey == null) {
            Certificate cert = keyStore.getCertificate(alias);
            if (cert != null)
                publicKey = cert.getPublicKey();
        }
        return publicKey;
    }
}

Related

  1. getPublicKey(KeyPair keyPair)
  2. getPublicKey(KeyPair keyPair)
  3. getPublicKey(KeyPair kp)
  4. getPublicKey(KeyStore keyStore, String alias)
  5. getPublicKey(KeyStore keyStore, String alias)
  6. getPublicKey(KeyStore ks, String alias, char[] password)
  7. getPublicKey(String algo)
  8. getPublicKey(String alias)
  9. getPublicKey(String certificatePath)