48
48
import org .bouncycastle .openpgp .PGPSecretKeyRingCollection ;
49
49
import org .bouncycastle .openpgp .PGPSignature ;
50
50
import org .bouncycastle .openpgp .PGPUtil ;
51
+ import org .bouncycastle .openpgp .operator .KeyFingerPrintCalculator ;
51
52
import org .bouncycastle .openpgp .operator .PBEDataDecryptorFactory ;
52
53
import org .bouncycastle .openpgp .operator .PGPDigestCalculator ;
53
54
import org .bouncycastle .openpgp .operator .PGPKeyEncryptionMethodGenerator ;
55
+ import org .bouncycastle .openpgp .operator .bc .BcKeyFingerprintCalculator ;
54
56
import org .bouncycastle .openpgp .operator .bc .BcPBEDataDecryptorFactory ;
55
57
import org .bouncycastle .openpgp .operator .bc .BcPBEKeyEncryptionMethodGenerator ;
56
58
import org .bouncycastle .openpgp .operator .bc .BcPGPContentSignerBuilder ;
@@ -75,6 +77,7 @@ public class CryptoUtil
75
77
{
76
78
77
79
private static final int RsaKeySize = 2048 ;
80
+ private static final KeyFingerPrintCalculator KEY_FINGERPRINT_CALCULATOR = new BcKeyFingerprintCalculator ();
78
81
79
82
public static String createChecksum (String keyCode , String packageCode )
80
83
{
@@ -247,7 +250,7 @@ public static String decryptKeycode(String privateKey, String encryptedKeycode)
247
250
248
251
try
249
252
{
250
- PGPObjectFactory pgpF = new PGPObjectFactory (in );
253
+ PGPObjectFactory pgpF = new PGPObjectFactory (in , KEY_FINGERPRINT_CALCULATOR );
251
254
PGPEncryptedDataList enc ;
252
255
253
256
Object o = pgpF .nextObject ();
@@ -266,7 +269,7 @@ public static String decryptKeycode(String privateKey, String encryptedKeycode)
266
269
Iterator it = enc .getEncryptedDataObjects ();
267
270
PGPPrivateKey sKey = null ;
268
271
PGPPublicKeyEncryptedData pbe = null ;
269
- PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection (PGPUtil .getDecoderStream (keyIn ));
272
+ PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection (PGPUtil .getDecoderStream (keyIn ), KEY_FINGERPRINT_CALCULATOR );
270
273
271
274
while (sKey == null && it .hasNext ())
272
275
{
@@ -280,7 +283,7 @@ public static String decryptKeycode(String privateKey, String encryptedKeycode)
280
283
}
281
284
282
285
InputStream clear = pbe .getDataStream (new BcPublicKeyDataDecryptorFactory (sKey ));
283
- PGPObjectFactory plainFact = new PGPObjectFactory (clear );
286
+ PGPObjectFactory plainFact = new PGPObjectFactory (clear , KEY_FINGERPRINT_CALCULATOR );
284
287
Object message = plainFact .nextObject ();
285
288
286
289
if (message instanceof PGPLiteralData )
@@ -325,7 +328,7 @@ public static String encryptKeycode(String publicKeyStr, String keycode) throws
325
328
try {
326
329
InputStream in =new ByteArrayInputStream (publicKeyStr .getBytes ());
327
330
in = PGPUtil .getDecoderStream (in );
328
- PGPPublicKeyRingCollection pgpPub = new PGPPublicKeyRingCollection (in );
331
+ PGPPublicKeyRingCollection pgpPub = new PGPPublicKeyRingCollection (in , KEY_FINGERPRINT_CALCULATOR );
329
332
PGPPublicKey key = null ;
330
333
Iterator rIt = pgpPub .getKeyRings ();
331
334
while (key == null && rIt .hasNext ()) {
@@ -387,7 +390,7 @@ public static String encryptKeycode(String publicKeyStr, String keycode) throws
387
390
public static void decryptFile (InputStream input , OutputStream output , String decryptionKey , Progress progress ) throws IOException , PGPException
388
391
{
389
392
input = PGPUtil .getDecoderStream (input );
390
- PGPObjectFactory pgpF = new PGPObjectFactory (input );
393
+ PGPObjectFactory pgpF = new PGPObjectFactory (input , KEY_FINGERPRINT_CALCULATOR );
391
394
PGPEncryptedDataList enc ;
392
395
Object o = pgpF .nextObject ();
393
396
@@ -405,14 +408,14 @@ public static void decryptFile(InputStream input, OutputStream output, String de
405
408
PBEDataDecryptorFactory pdf = new BcPBEDataDecryptorFactory (decryptionKey .toCharArray (), bcPgp );
406
409
407
410
InputStream clear = pbe .getDataStream (pdf );
408
- PGPObjectFactory pgpFact = new PGPObjectFactory (clear );
411
+ PGPObjectFactory pgpFact = new PGPObjectFactory (clear , KEY_FINGERPRINT_CALCULATOR );
409
412
410
413
o = pgpFact .nextObject ();
411
414
412
415
if (o instanceof PGPCompressedData )
413
416
{
414
417
PGPCompressedData cData = (PGPCompressedData ) o ;
415
- pgpFact = new PGPObjectFactory (cData .getDataStream ());
418
+ pgpFact = new PGPObjectFactory (cData .getDataStream (), KEY_FINGERPRINT_CALCULATOR );
416
419
o = pgpFact .nextObject ();
417
420
}
418
421
@@ -455,7 +458,7 @@ public static String decryptMessage(String message, String decryptionKey) throws
455
458
InputStream in = new ByteArrayInputStream (encrypted );
456
459
in = PGPUtil .getDecoderStream (in );
457
460
458
- PGPObjectFactory pgpF = new PGPObjectFactory (in );
461
+ PGPObjectFactory pgpF = new PGPObjectFactory (in , KEY_FINGERPRINT_CALCULATOR );
459
462
PGPEncryptedDataList enc = null ;
460
463
Object o = pgpF .nextObject ();
461
464
@@ -474,7 +477,7 @@ public static String decryptMessage(String message, String decryptionKey) throws
474
477
PBEDataDecryptorFactory pdf = new BcPBEDataDecryptorFactory (decryptionKey .toCharArray (), bcPgp );
475
478
InputStream clear = pbe .getDataStream (pdf );
476
479
477
- PGPObjectFactory pgpFact = new PGPObjectFactory (clear );
480
+ PGPObjectFactory pgpFact = new PGPObjectFactory (clear , KEY_FINGERPRINT_CALCULATOR );
478
481
479
482
PGPLiteralData ld = (PGPLiteralData )pgpFact .nextObject ();
480
483
0 commit comments