Class SecretKey

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

public final class SecretKey extends Key

A symmetric secret key. Used with Cipher (AES) and Hmac (via raw bytes). For asymmetric algorithms use PublicKey / PrivateKey.

Keys carry the raw key material plus the algorithm name they are intended for. They do not enforce length or strength -- that is the caller's responsibility, although KeyGenerator will produce keys of standard lengths.

  • Constructor Summary

    Constructors
    Constructor
    Description
    SecretKey(String algorithm, byte[] keyBytes)
    Wraps existing key material.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the length of the key in bits.

    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
  • Constructor Details

    • SecretKey

      public SecretKey(String algorithm, byte[] keyBytes)

      Wraps existing key material.

      Parameters
      • algorithm: algorithm identifier (e.g. "AES")

      • keyBytes: raw key material -- defensively copied

  • Method Details

    • getBitLength

      public int getBitLength()
      Returns the length of the key in bits.