Skip to content

Commit

Permalink
Merge pull request #294 from beth-soptim/AES_CryptoSessionKeyProvider
Browse files Browse the repository at this point in the history
Fix: Removed "duplicated" ICryptoSessionKeyProvider instances for AES keys
  • Loading branch information
phax authored Jan 6, 2025
2 parents be88f33 + cd7426f commit 5ab089a
Showing 1 changed file with 12 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@
public interface ICryptoSessionKeyProvider
{
/**
* Get or create a new symmetric session key. This method may only throws
* Get or create a new symmetric session key. This method may only throw
* unchecked exceptions.
*
* @return A new session key. Must not be <code>null</code>.
*/
@Nonnull
SecretKey getSessionKey ();

/**
* Session key provider for AES-128 keys that can be used e.g. for AES-128-CBC or AES-128-GCM
*/
ICryptoSessionKeyProvider INSTANCE_RANDOM_AES_128 = () -> {
try
{
Expand All @@ -47,18 +50,12 @@ public interface ICryptoSessionKeyProvider
}
};

ICryptoSessionKeyProvider INSTANCE_RANDOM_AES_128_GCM = () -> {
try
{
final KeyGenerator aKeyGen = KeyUtils.getKeyGenerator (WSS4JConstants.AES_128_GCM);
return aKeyGen.generateKey ();
}
catch (final WSSecurityException ex)
{
throw new IllegalStateException ("Failed to create session key (AES-128-GCM)", ex);
}
};
@Deprecated (forRemoval = true, since = "3.0.2")
ICryptoSessionKeyProvider INSTANCE_RANDOM_AES_128_GCM = INSTANCE_RANDOM_AES_128;

/**
* Session key provider for AES-256 keys that can be used e.g. for AES-256-CBC or AES-256-GCM
*/
ICryptoSessionKeyProvider INSTANCE_RANDOM_AES_256 = () -> {
try
{
Expand All @@ -71,15 +68,7 @@ public interface ICryptoSessionKeyProvider
}
};

ICryptoSessionKeyProvider INSTANCE_RANDOM_AES_256_GCM = () -> {
try
{
final KeyGenerator aKeyGen = KeyUtils.getKeyGenerator (WSS4JConstants.AES_256_GCM);
return aKeyGen.generateKey ();
}
catch (final WSSecurityException ex)
{
throw new IllegalStateException ("Failed to create session key (AES-256-GCM)", ex);
}
};
@Deprecated (forRemoval = true, since = "3.0.2")
ICryptoSessionKeyProvider INSTANCE_RANDOM_AES_256_GCM = INSTANCE_RANDOM_AES_256;

}

0 comments on commit 5ab089a

Please sign in to comment.