private static PGPPublicKey certifiedPublicKey(
      int certificationLevel,
      PGPKeyPair keyPair,
      String id,
      PGPSignatureSubpacketVector hashedPcks,
      PGPSignatureSubpacketVector unhashedPcks,
      PGPContentSignerBuilder certificationSignerBuilder)
      throws PGPException {
    PGPSignatureGenerator sGen;

    try {
      sGen = new PGPSignatureGenerator(certificationSignerBuilder);
    } catch (Exception e) {
      throw new PGPException("creating signature generator: " + e, e);
    }

    //
    // generate the certification
    //
    sGen.init(certificationLevel, keyPair.getPrivateKey());

    sGen.setHashedSubpackets(hashedPcks);
    sGen.setUnhashedSubpackets(unhashedPcks);

    try {
      PGPSignature certification = sGen.generateCertification(id, keyPair.getPublicKey());

      return PGPPublicKey.addCertification(keyPair.getPublicKey(), id, certification);
    } catch (Exception e) {
      throw new PGPException("exception doing certification: " + e, e);
    }
  }
 /**
  * Construct a PGPSecretKey using the passed in private/public key pair and binding it to the
  * passed in id using a generated certification of certificationLevel.
  *
  * @param certificationLevel the type of certification to be added.
  * @param keyPair the public/private keys to use.
  * @param id the id to bind to the key.
  * @param checksumCalculator a calculator for the private key checksum.
  * @param hashedPcks the hashed packets to be added to the certification.
  * @param unhashedPcks the unhashed packets to be added to the certification.
  * @param certificationSignerBuilder the builder for generating the certification.
  * @param keyEncryptor an encryptor for the key if required (null otherwise).
  * @throws PGPException if there is an issue creating the secret key packet or the certification.
  */
 public PGPSecretKey(
     int certificationLevel,
     PGPKeyPair keyPair,
     String id,
     PGPDigestCalculator checksumCalculator,
     PGPSignatureSubpacketVector hashedPcks,
     PGPSignatureSubpacketVector unhashedPcks,
     PGPContentSignerBuilder certificationSignerBuilder,
     PBESecretKeyEncryptor keyEncryptor)
     throws PGPException {
   this(
       keyPair.getPrivateKey(),
       certifiedPublicKey(
           certificationLevel, keyPair, id, hashedPcks, unhashedPcks, certificationSignerBuilder),
       checksumCalculator,
       true,
       keyEncryptor);
 }