public synchronized void engineStore(OutputStream stream,char[] password) throws IOException, NoSuchAlgorithmException, CertificateException {
  if (password == null) {
    throw new IllegalArgumentException("password can't be null");
  }
  DerOutputStream pfx=new DerOutputStream();
  DerOutputStream version=new DerOutputStream();
  version.putInteger(VERSION_3);
  byte[] pfxVersion=version.toByteArray();
  pfx.write(pfxVersion);
  DerOutputStream authSafe=new DerOutputStream();
  DerOutputStream authSafeContentInfo=new DerOutputStream();
  if (privateKeyCount > 0 || secretKeyCount > 0) {
    if (debug != null) {
      debug.println("Storing " + (privateKeyCount + secretKeyCount) + " protected key(s) in a PKCS#7 data content-type");
    }
    byte[] safeContentData=createSafeContent();
    ContentInfo dataContentInfo=new ContentInfo(safeContentData);
    dataContentInfo.encode(authSafeContentInfo);
  }
  if (certificateCount > 0) {
    if (debug != null) {
      debug.println("Storing " + certificateCount + " certificate(s) in a PKCS#7 encryptedData content-type");
    }
    byte[] encrData=createEncryptedData(password);
    ContentInfo encrContentInfo=new ContentInfo(ContentInfo.ENCRYPTED_DATA_OID,new DerValue(encrData));
    encrContentInfo.encode(authSafeContentInfo);
  }
  DerOutputStream cInfo=new DerOutputStream();
  cInfo.write(DerValue.tag_SequenceOf,authSafeContentInfo);
  byte[] authenticatedSafe=cInfo.toByteArray();
  ContentInfo contentInfo=new ContentInfo(authenticatedSafe);
  contentInfo.encode(authSafe);
  byte[] authSafeData=authSafe.toByteArray();
  pfx.write(authSafeData);
  byte[] macData=calculateMac(password,authenticatedSafe);
  pfx.write(macData);
  DerOutputStream pfxout=new DerOutputStream();
  pfxout.write(DerValue.tag_Sequence,pfx);
  byte[] pfxData=pfxout.toByteArray();
  stream.write(pfxData);
  stream.flush();
}

public synchronized void engineStore ( OutputStream stream , char [ ] password ) throws IOException , NoSuchAlgorithmException , CertificateException { if ( password == null ) { throw new IllegalArgumentException ( "password can't be null" ) ; } DerOutputStream pfx = new DerOutputStream ( ) ; DerOutputStream version = new DerOutputStream ( ) ; version . putInteger ( VERSION_3 ) ; byte [ ] pfxVersion = version . toByteArray ( ) ; pfx . write ( pfxVersion ) ; DerOutputStream authSafe = new DerOutputStream ( ) ; DerOutputStream authSafeContentInfo = new DerOutputStream ( ) ; if ( privateKeyCount > 0 || secretKeyCount > 0 ) { if ( debug != null ) { debug . println ( "Storing " + ( privateKeyCount + secretKeyCount ) + " protected key(s) in a PKCS#7 data content-type" ) ; } byte [ ] safeContentData = createSafeContent ( ) ; ContentInfo dataContentInfo = new ContentInfo ( safeContentData ) ; dataContentInfo . encode ( authSafeContentInfo ) ; } if ( certificateCount > 0 ) { if ( debug != null ) { debug . println ( "Storing " + certificateCount + " certificate(s) in a PKCS#7 encryptedData content-type" ) ; } byte [ ] encrData = createEncryptedData ( password ) ; ContentInfo encrContentInfo = new ContentInfo ( ContentInfo . ENCRYPTED_DATA_OID , new DerValue ( encrData ) ) ; encrContentInfo . encode ( authSafeContentInfo ) ; } DerOutputStream cInfo = new DerOutputStream ( ) ; cInfo . write ( DerValue . tag_SequenceOf , authSafeContentInfo ) ; byte [ ] authenticatedSafe = cInfo . toByteArray ( ) ; ContentInfo contentInfo = new ContentInfo ( authenticatedSafe ) ; contentInfo . encode ( authSafe ) ; byte [ ] authSafeData = authSafe . toByteArray ( ) ; pfx . write ( authSafeData ) ; byte [ ] macData = calculateMac ( password , authenticatedSafe ) ; pfx . write ( macData ) ; DerOutputStream pfxout = new DerOutputStream ( ) ; pfxout . write ( DerValue . tag_Sequence , pfx ) ; byte [ ] pfxData = pfxout . toByteArray ( ) ; stream . write ( pfxData ) ; stream . flush ( ) ; }
stores this keystore to the given output stream , and protects its integrity with the given password .
