java.lang.Object
net.i2p.crypto.HMAC256Generator.HMACKey
All Implemented Interfaces:
Serializable, Key, SecretKey, Destroyable
Enclosing class:
HMAC256Generator

static final class HMAC256Generator.HMACKeyextends Object implements SecretKey
Performance-optimized SecretKey implementation for HMAC operations.

This class provides an efficient SecretKey implementation that avoids unnecessary key data copying during construction for improved performance. Unlike standard SecretKeySpec, this implementation maintains a direct reference to the key data while maintaining compatibility with Mac operations.

Implementation Note: HmacSHA256 only uses the first 32 bytes of the key, so getEncoded() returns exactly those 32 bytes (zero padded if the caller supplied a shorter key); the full key data may be longer than 32 bytes. The copy is mandatory rather than an optimization: the JDK's HmacCore.engineInit() zeroes the array returned by getEncoded() once it has consumed it, so handing out the internal array would destroy the caller's key. This also means the result must never be cached - a second init() with the same key object would read back an all-zero key.

  • Field Details

    • _data

      private final byte[] _data
      The data being authenticated.
  • Constructor Details

    • HMACKey

      public HMACKey(byte[] data)
      Key data.
      Parameters:
      data - the key data
  • Method Details