@@ -1259,14 +1259,20 @@ public synchronized void engineStore(OutputStream stream, char[] password)
1259
1259
" certificate(s) in a PKCS#7 encryptedData" );
1260
1260
}
1261
1261
1262
- byte [] encrData = createEncryptedData (password );
1263
- if (!certProtectionAlgorithm .equalsIgnoreCase ("NONE" )) {
1262
+ byte [] certsData = getCertificateData ();
1263
+ if (password != null && !certProtectionAlgorithm .equalsIgnoreCase ("NONE" )) {
1264
+ // -- SEQUENCE of EncryptedData
1265
+ DerOutputStream encrData = new DerOutputStream ();
1266
+ encrData .putInteger (0 );
1267
+ encrData .write (encryptContent (certsData , password ));
1268
+ DerOutputStream encrDataContent = new DerOutputStream ();
1269
+ encrDataContent .write (DerValue .tag_Sequence , encrData );
1264
1270
ContentInfo encrContentInfo =
1265
1271
new ContentInfo (ContentInfo .ENCRYPTED_DATA_OID ,
1266
- new DerValue (encrData ));
1272
+ new DerValue (encrDataContent . toByteArray () ));
1267
1273
encrContentInfo .encode (authSafeContentInfo );
1268
1274
} else {
1269
- ContentInfo dataContentInfo = new ContentInfo (encrData );
1275
+ ContentInfo dataContentInfo = new ContentInfo (certsData );
1270
1276
dataContentInfo .encode (authSafeContentInfo );
1271
1277
}
1272
1278
}
@@ -1289,7 +1295,7 @@ public synchronized void engineStore(OutputStream stream, char[] password)
1289
1295
if (macIterationCount < 0 ) {
1290
1296
macIterationCount = defaultMacIterationCount ();
1291
1297
}
1292
- if (!macAlgorithm .equalsIgnoreCase ("NONE" )) {
1298
+ if (password != null && !macAlgorithm .equalsIgnoreCase ("NONE" )) {
1293
1299
byte [] macData = calculateMac (password , authenticatedSafe );
1294
1300
pfx .write (macData );
1295
1301
}
@@ -1704,12 +1710,11 @@ private byte[] getBagAttributes(String alias, byte[] keyId,
1704
1710
}
1705
1711
1706
1712
/*
1707
- * Create EncryptedData content type, that contains EncryptedContentInfo.
1708
- * Includes certificates in individual SafeBags of type CertBag.
1709
- * Each CertBag may include pkcs12 attributes
1713
+ * Create Data content type, includes certificates in individual
1714
+ * SafeBags of type CertBag. Each CertBag may include pkcs12 attributes
1710
1715
* (see comments in getBagAttributes)
1711
1716
*/
1712
- private byte [] createEncryptedData ( char [] password )
1717
+ private byte [] getCertificateData ( )
1713
1718
throws CertificateException , IOException
1714
1719
{
1715
1720
DerOutputStream out = new DerOutputStream ();
@@ -1803,22 +1808,7 @@ private byte[] createEncryptedData(char[] password)
1803
1808
// wrap as SequenceOf SafeBag
1804
1809
DerOutputStream safeBagValue = new DerOutputStream ();
1805
1810
safeBagValue .write (DerValue .tag_SequenceOf , out );
1806
- byte [] safeBagData = safeBagValue .toByteArray ();
1807
-
1808
- // encrypt the content (EncryptedContentInfo)
1809
- if (!certProtectionAlgorithm .equalsIgnoreCase ("NONE" )) {
1810
- byte [] encrContentInfo = encryptContent (safeBagData , password );
1811
-
1812
- // -- SEQUENCE of EncryptedData
1813
- DerOutputStream encrData = new DerOutputStream ();
1814
- DerOutputStream encrDataContent = new DerOutputStream ();
1815
- encrData .putInteger (0 );
1816
- encrData .write (encrContentInfo );
1817
- encrDataContent .write (DerValue .tag_Sequence , encrData );
1818
- return encrDataContent .toByteArray ();
1819
- } else {
1820
- return safeBagData ;
1821
- }
1811
+ return safeBagValue .toByteArray ();
1822
1812
}
1823
1813
1824
1814
/*
0 commit comments