AuthenticatedSafe auth = new AuthenticatedSafe(c);
bOut.reset();
BEROutputStream berOut = new BEROutputStream(bOut);
berOut.writeObject(auth);
byte[] pkg = bOut.toByteArray();
ContentInfo mainInfo = new ContentInfo(data, new BERConstructedOctetString(pkg));
//
// create the mac
//
byte[] mSalt = new byte[20];
int itCount = MIN_ITERATIONS;
random.nextBytes(mSalt);
byte[] data = ((ASN1OctetString)mainInfo.getContent()).getOctets();
MacData mData = null;
try
{
Mac mac = Mac.getInstance(id_SHA1.getId(), "BC");
SecretKeyFactory keyFact = SecretKeyFactory.getInstance(id_SHA1.getId(), "BC");
PBEParameterSpec defParams = new PBEParameterSpec(mSalt, itCount);
PBEKeySpec pbeSpec = new PBEKeySpec(password);
mac.init(keyFact.generateSecret(pbeSpec), defParams);
mac.update(data);
byte[] res = mac.doFinal();
AlgorithmIdentifier algId = new AlgorithmIdentifier(id_SHA1, new DERNull());
DigestInfo dInfo = new DigestInfo(algId, res);
mData = new MacData(dInfo, mSalt, itCount);
}
catch (Exception e)
{
throw new IOException("error constructing MAC: " + e.toString());
}
//
// output the Pfx
//
Pfx pfx = new Pfx(mainInfo, mData);
berOut = new BEROutputStream(stream);
berOut.writeObject(pfx);
}