Record Class EncapsulatedSecret

java.lang.Object
java.lang.Record
net.jrodolfo.java_evolution.java21.key_encapsulation.EncapsulatedSecret
Record Components:
secretKey - the sender-side shared secret
encapsulation - the message sent to the receiver

public record EncapsulatedSecret(SecretKey secretKey, byte[] encapsulation) extends Record
Holds the two pieces produced by the sender side of a KEM exchange.

The secretKey is local key material. It is not sent over the network. The encapsulation is the byte message that can be sent to the receiver. The receiver combines that message with its private key to recover the same shared secret.

  • Constructor Details

    • EncapsulatedSecret

      public EncapsulatedSecret(SecretKey secretKey, byte[] encapsulation)
      Creates an immutable holder for the encapsulation bytes.
  • Method Details

    • encapsulation

      public byte[] encapsulation()
      Returns the value of the encapsulation record component.
      Returns:
      the value of the encapsulation record component
    • secretBytes

      public byte[] secretBytes()
      Returns the encoded shared secret bytes for demonstration and testing.

      Real applications should usually pass key material into a key derivation step instead of printing or comparing raw bytes directly.

      Returns:
      a defensive copy of the sender-side secret bytes
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • secretKey

      public SecretKey secretKey()
      Returns the value of the secretKey record component.
      Returns:
      the value of the secretKey record component