Class Key

java.lang.Object
com.codename1.security.Key
Direct Known Subclasses:
PrivateKey, PublicKey, SecretKey

public abstract class Key extends Object

Common base for every key type in the security package -- SecretKey for symmetric algorithms, PublicKey and PrivateKey for asymmetric ones.

Holds the three pieces of metadata every key carries:

  • an algorithm name (e.g. "AES", "RSA", "EC")
  • a defensive copy of the encoded key bytes
  • a format identifier (e.g. "RAW" for symmetric keys, "X.509" for SPKI public keys, "PKCS#8" for private keys)

Application code should not extend this class directly; create the concrete subtype that matches the algorithm you are using.

  • Constructor Details

    • Key

      protected Key(String algorithm, byte[] encoded, String format)
      Parameters
      • algorithm: human-readable algorithm name (e.g. "AES")

      • encoded: raw key material -- defensively copied

      • format: encoding format identifier ("RAW", "X.509", "PKCS#8")

  • Method Details

    • getEncoded

      public final byte[] getEncoded()
      Returns a fresh copy of the encoded key bytes. Treat returns from private keys as sensitive material -- do not log or store unencrypted.
    • getAlgorithm

      public final String getAlgorithm()
      Returns the algorithm this key is intended for (e.g. "AES", "RSA").
    • getFormat

      public final String getFormat()

      Returns the encoding format identifier. Standard values: