Class EncryptionKey

java.lang.Object
org.apache.pulsar.client.api.v5.auth.EncryptionKey

public final class EncryptionKey extends Object
A single encryption / decryption key returned by a PublicKeyProvider or PrivateKeyProvider.

The producer-side flow returns just the key bytes. The consumer-side flow may include metadata() that the producer attached when the message was encrypted (e.g. a key version) — the PrivateKeyProvider can use it to pick the right private key when keys have been rotated.

Use of(byte[]) when there's no metadata, or of(byte[], Map) to attach producer-side hints alongside the bytes.

  • Method Details

    • key

      public byte[] key()
      Returns:
      the raw key bytes
    • metadata

      public Map<String,String> metadata()
      Returns:
      key-value metadata associated with the key (never null; empty when the producer did not attach any)
    • of

      public static EncryptionKey of(byte[] key)
      Create an EncryptionKey with no metadata.
      Parameters:
      key - the raw key bytes
      Returns:
      a new EncryptionKey
    • of

      public static EncryptionKey of(byte[] key, Map<String,String> metadata)
      Create an EncryptionKey with associated metadata.
      Parameters:
      key - the raw key bytes
      metadata - key-value metadata to attach to the key
      Returns:
      a new EncryptionKey