# Class PublicKey

java.lang.Object
com.codename1.security.Key
com.codename1.security.PublicKey

public final class PublicKey extends Key

A public key -- paired with a `PrivateKey` to form a key pair. Carries the algorithm name ("RSA" or "EC") and the encoded key bytes.

For interop with PEM files (`-----BEGIN PUBLIC KEY-----`) feed the X.509-SubjectPublicKeyInfo (SPKI) DER bytes to `fromX509(String, byte[])`; for raw RSA modulus/exponent use `rsa(byte[])`.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `EC`
  Elliptic-curve algorithm identifier ("EC").
  `static final String`
  `RSA`
  RSA algorithm identifier ("RSA").

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static PublicKey`
  `fromX509(String algorithm, byte[] x509Der)`
  Wraps an X.509 / SubjectPublicKeyInfo (SPKI) DER blob.
  `static PublicKey`
  `rsa(byte[] x509Der)`
  Convenience: build an RSA `PublicKey` from a `fromX509(String, byte[])` X.509 blob.

  ### Methods inherited from class Key

  `getAlgorithm, getEncoded, getFormat`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### RSA

    public static final String RSA
    RSA algorithm identifier ("RSA").
    See Also:
      - Constant Field Values

  - ### EC

    public static final String EC
    Elliptic-curve algorithm identifier ("EC").
    See Also:
      - Constant Field Values

- ## Method Details

  - ### fromX509

    public static PublicKey fromX509(String algorithm, byte[] x509Der)
    Wraps an X.509 / SubjectPublicKeyInfo (SPKI) DER blob. This is the format produced by `openssl rsa -pubout` or `openssl ec -pubout`.

  - ### rsa

    public static PublicKey rsa(byte[] x509Der)
    Convenience: build an RSA `PublicKey` from a `fromX509(String, byte[])` X.509 blob.