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

PublicKeygetPublic(byte[] encodedKey)
The method gets the public key from the encoded byte.
return kf.generatePublic(new X509EncodedKeySpec(encodedKey));
PublicKeygetPublic(byte[] keyBytes)
Gets the public key from bytes.
try {
    X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes);
    KeyFactory kf = KeyFactory.getInstance("RSA");
    return kf.generatePublic(spec);
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
    throw new InvalidKeyException(e);
byte[]getPublicBytes(KeyPair keyPair)
get Public Bytes
return keyPair.getPublic().getEncoded();
Method[]getPublicDeclaredMethods(Class clz)
Get the methods declared as public within the class
Method[] result = null;
final Class fclz = clz;
Reference ref = (Reference) declaredMethodCache.get(fclz);
if (ref != null) {
    result = (Method[]) ref.get();
    if (result != null) {
        return result;
result = (Method[]) AccessController.doPrivileged(new PrivilegedAction() {
    public Object run() {
        return fclz.getDeclaredMethods();
});
for (int i = 0; i < result.length; i++) {
    Method method = result[i];
    int mods = method.getModifiers();
    if (!Modifier.isPublic(mods)) {
        result[i] = null;
declaredMethodCache.put(fclz, new SoftReference(result));
return result;
Method[]getPublicDeclaredMethods(Class clz)
get Public Declared Methods
final Class fclz = clz;
Method[] result = (Method[]) declaredMethodCache.get(fclz);
if (result != null) {
    return result;
result = (Method[]) AccessController.doPrivileged(new PrivilegedAction() {
    public Object run() {
        try {
...
StringgetPublicEncoded(KeyPair kp)
get Public Encoded
return getPublicEncoded(kp.getPublic());
byte[]getPublicExponent(PublicKey pubk)
get Public Exponent
RSAPublicKey rsaKey = (RSAPublicKey) pubk;
return rsaKey.getPublicExponent().toByteArray();
StringgetPublicKey()
get Public Key
Key key = (Key) keyMap.get(PUBLIC_KEY);
byte[] bytes = key.getEncoded();
BASE64Encoder base64Encoder = new BASE64Encoder();
return base64Encoder.encode(bytes);
RSAPublicKeygetPublicKey(BigInteger modulus, BigInteger exponent)
get Public Key
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
RSAPublicKeySpec keySpec = new RSAPublicKeySpec(modulus, exponent);
return (RSAPublicKey) keyFactory.generatePublic(keySpec);
PublicKeygetPublicKey(byte[] der)
get Public Key
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
X509EncodedKeySpec pubSpec = new X509EncodedKeySpec(der);
RSAPublicKey pubKey = (RSAPublicKey) keyFactory.generatePublic(pubSpec);
return pubKey;