Class SecurityIntegrationExamples

java.lang.Object
net.jrodolfo.java_evolution.java04.security.SecurityIntegrationExamples

public class SecurityIntegrationExamples extends Object
Demonstrates local security APIs integrated into the standard platform.

J2SE 1.4 integrated JCE, JSSE, and JAAS into the platform. This executable example focuses on local Java Cryptography Architecture (JCA) and Java Cryptography Extension (JCE) operations because they are deterministic, portable, and do not require sockets, login configuration, credentials, or external services.

  • Constructor Details

    • SecurityIntegrationExamples

      public SecurityIntegrationExamples()
  • Method Details

    • providerServicesFor

      public List providerServicesFor(String algorithm)
      Lists provider services for a given algorithm.
      Parameters:
      algorithm - algorithm to find, such as SHA-256
      Returns:
      provider/service summaries
    • sha256Digest

      public byte[] sha256Digest(String text) throws GeneralSecurityException
      Computes a SHA-256 digest.
      Parameters:
      text - text to digest
      Returns:
      digest bytes
      Throws:
      GeneralSecurityException - when SHA-256 is unavailable
    • secureRandomBytes

      public byte[] secureRandomBytes(int length)
      Generates random bytes with SecureRandom.
      Parameters:
      length - number of bytes to generate
      Returns:
      random bytes
    • generateAesKey

      public SecretKey generateAesKey() throws GeneralSecurityException
      Generates an AES key with the platform provider.
      Returns:
      generated AES key
      Throws:
      GeneralSecurityException - when AES key generation is unavailable
    • hmacSha1

      public byte[] hmacSha1(String message) throws GeneralSecurityException
      Computes an HMAC-SHA1 tag for this historical provider example.
      Parameters:
      message - message to authenticate
      Returns:
      authentication tag
      Throws:
      GeneralSecurityException - when HMAC-SHA1 is unavailable
    • verifyHmacSha1

      public boolean verifyHmacSha1(String message, byte[] expectedTag) throws GeneralSecurityException
      Verifies an HMAC-SHA1 tag using constant-time comparison.
      Parameters:
      message - authenticated message
      expectedTag - expected authentication tag
      Returns:
      whether the tag matches the message
      Throws:
      GeneralSecurityException - when HMAC-SHA1 is unavailable
    • generateRsaKeyPair

      public KeyPair generateRsaKeyPair() throws GeneralSecurityException
      Generates an RSA key pair for the signature example.
      Returns:
      generated key pair
      Throws:
      GeneralSecurityException - when RSA key generation is unavailable
    • signWithRsa

      public byte[] signWithRsa(String message, KeyPair keyPair) throws GeneralSecurityException
      Signs a message with SHA256withRSA.
      Parameters:
      message - message to sign
      keyPair - signing key pair
      Returns:
      signature bytes
      Throws:
      GeneralSecurityException - when signing fails
    • verifyRsaSignature

      public boolean verifyRsaSignature(String message, byte[] signed, KeyPair keyPair) throws GeneralSecurityException
      Verifies a SHA256withRSA signature.
      Parameters:
      message - signed message
      signed - signature bytes
      keyPair - key pair whose public key should verify the signature
      Returns:
      whether the signature is valid for the message
      Throws:
      GeneralSecurityException - when verification fails