2222import java .nio .ByteBuffer ;
2323import java .security .GeneralSecurityException ;
2424import java .security .Key ;
25+ import java .security .NoSuchAlgorithmException ;
2526import java .security .SecureRandom ;
2627import java .util .Random ;
2728
3031import javax .crypto .spec .IvParameterSpec ;
3132import javax .crypto .spec .SecretKeySpec ;
3233
34+ import edu .umd .cs .findbugs .annotations .SuppressFBWarnings ;
3335import io .wcm .devops .conga .plugins .aem .crypto .CryptoSupport ;
3436
3537/**
@@ -45,13 +47,15 @@ public class AesCryptoSupport extends CryptoSupport {
4547
4648 private static final String SECURE_RANDOM_ALGORITHM = "SHA1PRNG" ;
4749
48- private final Random random ;
50+ private static final Random RANDOM = initRandom () ;
4951
50- /**
51- * @throws GeneralSecurityException Security exception
52- */
53- public AesCryptoSupport () throws GeneralSecurityException {
54- this .random = SecureRandom .getInstance (SECURE_RANDOM_ALGORITHM );
52+ private static Random initRandom () {
53+ try {
54+ return SecureRandom .getInstance (SECURE_RANDOM_ALGORITHM );
55+ }
56+ catch (NoSuchAlgorithmException ex ) {
57+ throw new RuntimeException (ex );
58+ }
5559 }
5660
5761 @ Override
@@ -91,9 +95,10 @@ private Cipher getCipher(int cipherMode, byte[] iv, Key key) throws GeneralSecur
9195 return cipher ;
9296 }
9397
98+ @ SuppressFBWarnings ("DMI_RANDOM_USED_ONLY_ONCE" )
9499 private byte [] generateIV () {
95100 byte [] iv = new byte [IV_SIZE ];
96- random .nextBytes (iv );
101+ RANDOM .nextBytes (iv );
97102 return iv ;
98103 }
99104
0 commit comments