44
44
import org .bouncycastle .openpgp .operator .jcajce .JcePBEDataDecryptorFactoryBuilder ;
45
45
import org .bouncycastle .openpgp .operator .jcajce .JcePBEKeyEncryptionMethodGenerator ;
46
46
import org .bouncycastle .openpgp .operator .jcajce .JcePGPDataEncryptorBuilder ;
47
+ import org .bouncycastle .test .DumpUtil ;
47
48
import org .bouncycastle .util .Arrays ;
48
49
import org .bouncycastle .util .Exceptions ;
49
50
import org .bouncycastle .util .Pack ;
@@ -174,11 +175,9 @@ private void knownV5TestVectorDecryptionTests()
174
175
throws IOException , PGPException
175
176
{
176
177
// test known-good V5 test vectors
177
- System .out .println ("Test V5 BC Decryption" );
178
178
testBcDecryption (V5_EAX_PACKET_SEQUENCE , PASSWORD , PLAINTEXT );
179
179
testBcDecryption (V5_OCB_PACKET_SEQUENCE , PASSWORD , PLAINTEXT );
180
180
testBcDecryption (V5_GCM_PACKET_SEQUENCE , PASSWORD , PLAINTEXT );
181
- System .out .println ("Test V5 JCA Decryption" );
182
181
testJceDecryption (V5_EAX_PACKET_SEQUENCE , PASSWORD , PLAINTEXT );
183
182
testJceDecryption (V5_OCB_PACKET_SEQUENCE , PASSWORD , PLAINTEXT );
184
183
testJceDecryption (V5_GCM_PACKET_SEQUENCE , PASSWORD , PLAINTEXT );
@@ -187,12 +186,10 @@ private void knownV5TestVectorDecryptionTests()
187
186
private void knownV6TestVectorDecryptionTests ()
188
187
throws IOException , PGPException
189
188
{
190
- // Test known-good V6 test vectors TODO: decryption tests should be working...
191
- System .out .println ("Test V6 BC Decryption" );
189
+ // Test known-good V6 test vectors TODO: decryption tests
192
190
testBcDecryption (V6_EAX_PACKET_SEQUENCE , PASSWORD , PLAINTEXT );
193
191
testBcDecryption (V6_OCB_PACKET_SEQUENCE , PASSWORD , PLAINTEXT );
194
192
testBcDecryption (V6_GCM_PACKET_SEQUENCE , PASSWORD , PLAINTEXT );
195
- System .out .println ("Test V6 JCA Decryption" );
196
193
testJceDecryption (V6_EAX_PACKET_SEQUENCE , PASSWORD , PLAINTEXT );
197
194
testJceDecryption (V6_OCB_PACKET_SEQUENCE , PASSWORD , PLAINTEXT );
198
195
testJceDecryption (V6_GCM_PACKET_SEQUENCE , PASSWORD , PLAINTEXT );
@@ -201,36 +198,28 @@ private void knownV6TestVectorDecryptionTests()
201
198
private void testBcRoundTrip (boolean v5AEAD , int aeadAlg , int symAlg , byte [] plaintext , char [] password )
202
199
throws PGPException , IOException
203
200
{
204
- System .out .println ("Test BC RoundTrip " + (v5AEAD ? "V5" : "V6" ) + " " + algNames (aeadAlg , symAlg ));
205
201
String armored = testBcEncryption (v5AEAD , aeadAlg , symAlg , plaintext , password );
206
- System .out .println (armored );
207
202
testBcDecryption (armored , password , plaintext );
208
203
}
209
204
210
205
private void testJceRoundTrip (boolean v5AEAD , int aeadAlg , int symAlg , byte [] plaintext , char [] password )
211
206
throws PGPException , IOException
212
207
{
213
- System .out .println ("Test JCE RoundTrip " + (v5AEAD ? "V5" : "V6" ) + " " + algNames (aeadAlg , symAlg ));
214
208
String armored = testJceEncryption (v5AEAD , aeadAlg , symAlg , plaintext , password );
215
- System .out .println (armored );
216
209
testJceDecryption (armored , password , plaintext );
217
210
}
218
211
219
212
private void testBcJceRoundTrip (boolean v5AEAD , int aeadAlg , int symAlg , byte [] plaintext , char [] password )
220
213
throws PGPException , IOException
221
214
{
222
- System .out .println ("Test BC encrypt, JCE decrypt " + (v5AEAD ? "V5" : "V6" ) + " " + algNames (aeadAlg , symAlg ));
223
215
String armored = testBcEncryption (v5AEAD , aeadAlg , symAlg , plaintext , password );
224
- System .out .println (armored );
225
216
testJceDecryption (armored , password , plaintext );
226
217
}
227
218
228
219
private void testJceBcRoundTrip (boolean v5AEAD , int aeadAlg , int symAlg , byte [] plaintext , char [] password )
229
220
throws PGPException , IOException
230
221
{
231
- System .out .println ("Test JCE encrypt, BC decrypt " + (v5AEAD ? "V5" : "V6" ) + " " + algNames (aeadAlg , symAlg ));
232
222
String armored = testJceEncryption (v5AEAD , aeadAlg , symAlg , plaintext , password );
233
- System .out .println (armored );
234
223
testBcDecryption (armored , password , plaintext );
235
224
}
236
225
@@ -365,7 +354,9 @@ private void testBcDecryption(String armoredMessage, char[] password, byte[] exp
365
354
366
355
if (o != null )
367
356
{
357
+ // -DM System.out.println
368
358
System .out .println ("Unexpected trailing packet." );
359
+ // -DM System.out.println
369
360
System .out .println (o );
370
361
}
371
362
}
@@ -421,7 +412,9 @@ private void testJceDecryption(String armoredMessage, char[] password, byte[] ex
421
412
422
413
if (o != null )
423
414
{
415
+ // -DM System.out.println
424
416
System .out .println ("Unexpected trailing packet." );
417
+ // -DM System.out.println
425
418
System .out .println (o );
426
419
}
427
420
}
@@ -435,30 +428,8 @@ private void testJceDecryption(String armoredMessage, char[] password, byte[] ex
435
428
436
429
public static void printHex (byte [] bytes )
437
430
{
438
- boolean separate = true ;
439
- boolean prefix = true ;
440
- String hex = Hex .toHexString (bytes );
441
- StringBuffer sb = new StringBuffer ();
442
- for (int i = 0 ; i < hex .length () / 2 ; i ++)
443
- {
444
- if (prefix && i % 8 == 0 )
445
- {
446
- sb .append ("0x" ).append (Hex .toHexString (Pack .intToBigEndian (i & 0xFFFFF ))).append (" " );
447
- }
448
- sb .append (hex .substring (i * 2 , i * 2 + 2 ));
449
- if (separate )
450
- {
451
- if ((i + 1 ) % 8 == 0 )
452
- {
453
- sb .append ('\n' );
454
- }
455
- else
456
- {
457
- sb .append (' ' );
458
- }
459
- }
460
- }
461
- System .out .println (sb );
431
+ // -DM System.out.println
432
+ System .out .println (DumpUtil .hexdump (bytes ));
462
433
}
463
434
464
435
private static String algNames (int aeadAlg , int symAlg )
0 commit comments