@@ -238,10 +238,10 @@ public void testNewEncryptDecrypt() {
238238 * strength crypto is not available for this Java VM.
239239 */
240240 private String runNewEncryptDecryptTestCase (String cipherXform , int keySize , byte [] plaintextBytes ) {
241- System .out .println ("New encrypt / decrypt: " + cipherXform );
241+ System .err .println ("New encrypt / decrypt: " + cipherXform + "; requested key size: " + keySize + " bits." );
242242
243243 if ( keySize > 128 && !unlimitedStrengthJurisdictionPolicyInstalled ) {
244- System .out .println ("Skipping test for cipher transformation " +
244+ System .err .println ("Skipping test for cipher transformation " +
245245 cipherXform + " with key size of " + keySize +
246246 " bits because this requires JCE Unlimited Strength" +
247247 " Jurisdiction Policy files to be installed and they" +
@@ -254,16 +254,21 @@ private String runNewEncryptDecryptTestCase(String cipherXform, int keySize, byt
254254 SecretKey skey = CryptoHelper .generateSecretKey (cipherXform , keySize );
255255 assertTrue ( skey .getAlgorithm ().equals (cipherXform .split ("/" )[0 ]) );
256256 String cipherAlg = cipherXform .split ("/" )[0 ];
257+
258+ System .err .println ("Key size of generated encoded key: " + skey .getEncoded ().length * 8 + " bits." );
257259
258260 // Adjust key size for DES and DESede specific oddities.
259261 // NOTE: Key size that encrypt() method is using is 192 bits!!!
260262 // which is 3 times 64 bits, but DES key size is only 56 bits.
261263 // See 'IMPORTANT NOTE', in JavaEncryptor, near line 376. It's a "feature"!!!
262264 if ( cipherAlg .equals ( "DESede" ) ) {
265+ System .err .println ("Adjusting requested key size of " + keySize + " bits to 192 bits for DESede" );
263266 keySize = 192 ;
264267 } else if ( cipherAlg .equals ( "DES" ) ) {
268+ System .err .println ("Adjusting requested key size of " + keySize + " bits to 64 bits for DES" );
265269 keySize = 64 ;
266270 } // Else... use specified keySize.
271+
267272 assertTrue (cipherXform + ": encoded key size of " + skey .getEncoded ().length + " shorter than requested key size of: " + (keySize / 8 ),
268273 skey .getEncoded ().length >= (keySize / 8 ) );
269274
@@ -273,7 +278,7 @@ private String runNewEncryptDecryptTestCase(String cipherXform, int keySize, byt
273278 @ SuppressWarnings ("deprecation" )
274279 String oldCipherXform = ESAPI .securityConfiguration ().setCipherTransformation (cipherXform );
275280 if ( ! cipherXform .equals (oldCipherXform ) ) {
276- System .out .println ("Cipher xform changed from \" " + oldCipherXform + "\" to \" " + cipherXform + "\" " );
281+ System .err .println ("Cipher xform changed from \" " + oldCipherXform + "\" to \" " + cipherXform + "\" " );
277282 }
278283
279284 // Get an Encryptor instance with the specified, possibly new, cipher transformation.
@@ -283,12 +288,12 @@ private String runNewEncryptDecryptTestCase(String cipherXform, int keySize, byt
283288
284289 // Do the encryption with the new encrypt() method and get back the CipherText.
285290 CipherText ciphertext = instance .encrypt (skey , plaintext ); // The new encrypt() method.
286- System .out .println ("DEBUG: Encrypt(): CipherText object is -- " + ciphertext );
291+ System .err .println ("DEBUG: Encrypt(): CipherText object is -- " + ciphertext );
287292 assertNotNull ( ciphertext );
288- // System.out .println("DEBUG: After encryption: base64-encoded IV+ciphertext: " + ciphertext.getEncodedIVCipherText());
289- // System.out .println("\t\tOr... " + ESAPI.encoder().decodeFromBase64(ciphertext.getEncodedIVCipherText()) );
290- // System.out .println("DEBUG: After encryption: base64-encoded raw ciphertext: " + ciphertext.getBase64EncodedRawCipherText());
291- // System.out .println("\t\tOr... " + ESAPI.encoder().decodeFromBase64(ciphertext.getBase64EncodedRawCipherText()) );
293+ // System.err .println("DEBUG: After encryption: base64-encoded IV+ciphertext: " + ciphertext.getEncodedIVCipherText());
294+ // System.err .println("\t\tOr... " + ESAPI.encoder().decodeFromBase64(ciphertext.getEncodedIVCipherText()) );
295+ // System.err .println("DEBUG: After encryption: base64-encoded raw ciphertext: " + ciphertext.getBase64EncodedRawCipherText());
296+ // System.err .println("\t\tOr... " + ESAPI.encoder().decodeFromBase64(ciphertext.getBase64EncodedRawCipherText()) );
292297
293298 // If we are supposed to have overwritten the plaintext, check this to see
294299 // if origPlainText was indeed overwritten.
0 commit comments