Java Utililty Methods Key Public

List of utility methods to do Key Public

Description

The list of methods to do Key Public are organized into topic(s).

Method

PublicKeygetPublicKey(byte[] keyBytes, String algorithm)
get Public Key
PublicKey publicKey = null;
try {
    KeyFactory kf = KeyFactory.getInstance(algorithm);
    EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
    publicKey = kf.generatePublic(keySpec);
} catch (NoSuchAlgorithmException e) {
    System.out.println("Could not reconstruct the public key, the given algorithm could not be found.");
} catch (InvalidKeySpecException e) {
...
PublicKeygetPublicKey(final byte[] keyData)
get Public Key
final X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyData);
final KeyFactory keyFactory = KeyFactory.getInstance("RSA");
return keyFactory.generatePublic(keySpec);
RSAPublicKeygetPublicKey(final byte[] modulus, final byte[] exponent)
get Public Key
final RSAPublicKeySpec spec = new RSAPublicKeySpec(new BigInteger(modulus), new BigInteger(exponent));
try {
    final KeyFactory factory = KeyFactory.getInstance(EBICS_ENCRYPTION_KEY_ALGORITHM);
    return (RSAPublicKey) factory.generatePublic(spec);
} catch (final GeneralSecurityException e) {
    throw new RuntimeException(e);
PublicKeygetPublicKey(final String algorithm, final File publicKeyFile)
get Public Key
return getPublicKeyFromBytes(algorithm, readBytes(publicKeyFile));
PublicKeygetPublicKey(KeyPair keyPair)
get Public Key
if (keyPair == null) {
    return null;
return keyPair.getPublic();
StringgetPublicKey(KeyPair keyPair)
get Public Key
PublicKey publicKey = keyPair.getPublic();
return toHexString(publicKey.getEncoded());
KeygetPublicKey(KeyPair kp)
get Public Key
return (kp != null) ? kp.getPublic() : null;
PublicKeygetPublicKey(KeyStore keyStore, String alias)
get Public Key
return getCertificate(keyStore, alias).getPublicKey();
PublicKeygetPublicKey(KeyStore keyStore, String alias)
get Public Key
return keyStore.getCertificate(alias).getPublicKey();
PublicKeygetPublicKey(KeyStore keyStore, String alias, char[] password)
get Public Key
PublicKey publicKey = null;
Key key = keyStore.getKey(alias, password);
if (key instanceof PrivateKey) {
    Certificate cert = keyStore.getCertificate(alias);
    publicKey = cert.getPublicKey();
if (publicKey == null) {
    Certificate cert = keyStore.getCertificate(alias);
...