Ejemplo n.º 1
0
  void addKeyBag(
      org.mozilla.jss.crypto.PrivateKey pkey,
      X509Certificate x509cert,
      Password pass,
      byte[] localKeyId,
      SEQUENCE safeContents)
      throws Exception {

    PasswordConverter passConverter = new PasswordConverter();
    byte salt[] = {0x01, 0x01, 0x01, 0x01};
    byte[] priData = getEncodedKey(pkey);

    PrivateKeyInfo pki = (PrivateKeyInfo) ASN1Util.decode(PrivateKeyInfo.getTemplate(), priData);

    ASN1Value key =
        EncryptedPrivateKeyInfo.createPBE(
            PBEAlgorithm.PBE_SHA1_DES3_CBC, pass, salt, 1, passConverter, pki);

    SET keyAttrs = createBagAttrs(x509cert.getSubjectDN().toString(), localKeyId);

    SafeBag keyBag = new SafeBag(SafeBag.PKCS8_SHROUDED_KEY_BAG, key, keyAttrs);

    safeContents.addElement(keyBag);
  }