Class SecurityIntegrationExamples
java.lang.Object
net.jrodolfo.java_evolution.java04.security.SecurityIntegrationExamples
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classSummarizes a provider service. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGenerates an AES key with the platform provider.Generates an RSA key pair for the signature example.byte[]Computes an HMAC-SHA1 tag for this historical provider example.providerServicesFor(String algorithm) Lists provider services for a given algorithm.byte[]secureRandomBytes(int length) Generates random bytes withSecureRandom.byte[]sha256Digest(String text) Computes a SHA-256 digest.byte[]signWithRsa(String message, KeyPair keyPair) Signs a message with SHA256withRSA.booleanverifyHmacSha1(String message, byte[] expectedTag) Verifies an HMAC-SHA1 tag using constant-time comparison.booleanverifyRsaSignature(String message, byte[] signed, KeyPair keyPair) Verifies a SHA256withRSA signature.
-
Constructor Details
-
SecurityIntegrationExamples
public SecurityIntegrationExamples()
-
-
Method Details
-
providerServicesFor
-
sha256Digest
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 withSecureRandom.- Parameters:
length- number of bytes to generate- Returns:
- random bytes
-
generateAesKey
Generates an AES key with the platform provider.- Returns:
- generated AES key
- Throws:
GeneralSecurityException- when AES key generation is unavailable
-
hmacSha1
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
Verifies an HMAC-SHA1 tag using constant-time comparison.- Parameters:
message- authenticated messageexpectedTag- expected authentication tag- Returns:
- whether the tag matches the message
- Throws:
GeneralSecurityException- when HMAC-SHA1 is unavailable
-
generateRsaKeyPair
Generates an RSA key pair for the signature example.- Returns:
- generated key pair
- Throws:
GeneralSecurityException- when RSA key generation is unavailable
-
signWithRsa
Signs a message with SHA256withRSA.- Parameters:
message- message to signkeyPair- 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 messagesigned- signature byteskeyPair- key pair whose public key should verify the signature- Returns:
- whether the signature is valid for the message
- Throws:
GeneralSecurityException- when verification fails
-