Program: 52359
Project: 52359
Buggy source:
/** 
 * Create a PGPPublicKey from the passed in JCA one. <p> Note: the time passed in affects the value of the key's keyID, so you probably only want to do this once for a JCA key, or make sure you keep track of the time you used. </p>
 * @param algorithm asymmetric algorithm type representing the public key.
 * @param pubKey    actual public key to associate.
 * @param time      date of creation.
 * @throws PGPException on key creation problem.
 */
public PGPPublicKey getPGPPublicKey(int algorithm,PGPAlgorithmParameters algorithmParameters,AsymmetricKeyParameter pubKey,Date time) throws PGPException {
  BCPGKey bcpgKey;
  if (pubKey instanceof RSAKeyParameters) {
    RSAKeyParameters rK=(RSAKeyParameters)pubKey;
    bcpgKey=new RSAPublicBCPGKey(rK.getModulus(),rK.getExponent());
  }
 else   if (pubKey instanceof DSAPublicKeyParameters) {
    DSAPublicKeyParameters dK=(DSAPublicKeyParameters)pubKey;
    DSAParameters dP=dK.getParameters();
    bcpgKey=new DSAPublicBCPGKey(dP.getP(),dP.getQ(),dP.getG(),dK.getY());
  }
 else   if (pubKey instanceof ElGamalPublicKeyParameters) {
    ElGamalPublicKeyParameters eK=(ElGamalPublicKeyParameters)pubKey;
    ElGamalParameters eS=eK.getParameters();
    bcpgKey=new ElGamalPublicBCPGKey(eS.getP(),eS.getG(),eK.getY());
  }
 else   if (pubKey instanceof ECPublicKeyParameters) {
    SubjectPublicKeyInfo keyInfo;
    try {
      keyInfo=SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(pubKey);
    }
 catch (    IOException e) {
      throw new PGPException("String_Node_Str" + e.getMessage(),e);
    }
    ASN1ObjectIdentifier curveOid=ASN1ObjectIdentifier.getInstance(keyInfo.getAlgorithm().getParameters());
    X9ECParameters params=NISTNamedCurves.getByOID(curveOid);
    ASN1OctetString key=new DEROctetString(keyInfo.getPublicKeyData().getBytes());
    X9ECPoint derQ=new X9ECPoint(params.getCurve(),key);
    if (algorithm == PGPPublicKey.ECDH) {
      PGPKdfParameters kdfParams=(PGPKdfParameters)algorithmParameters;
      if (kdfParams == null) {
        kdfParams=new PGPKdfParameters(HashAlgorithmTags.SHA256,SymmetricKeyAlgorithmTags.AES_128);
      }
      bcpgKey=new ECDHPublicBCPGKey(curveOid,derQ.getPoint(),kdfParams.getHashAlgorithm(),kdfParams.getSymmetricWrapAlgorithm());
    }
 else     if (algorithm == PGPPublicKey.ECDSA) {
      bcpgKey=new ECDSAPublicBCPGKey(curveOid,derQ.getPoint());
    }
 else {
      throw new PGPException("String_Node_Str");
    }
  }
 else {
    throw new PGPException("String_Node_Str");
  }
  return new PGPPublicKey(new PublicKeyPacket(algorithm,time,bcpgKey),new BcKeyFingerprintCalculator());
}

Fixed version (ground truth):
/** 
 * Create a PGPPublicKey from the passed in JCA one. <p> Note: the time passed in affects the value of the key's keyID, so you probably only want to do this once for a JCA key, or make sure you keep track of the time you used. </p>
 * @param algorithm asymmetric algorithm type representing the public key.
 * @param pubKey    actual public key to associate.
 * @param time      date of creation.
 * @throws PGPException on key creation problem.
 */
public PGPPublicKey getPGPPublicKey(int algorithm,PGPAlgorithmParameters algorithmParameters,AsymmetricKeyParameter pubKey,Date time) throws PGPException {
  BCPGKey bcpgKey;
  if (pubKey instanceof RSAKeyParameters) {
    RSAKeyParameters rK=(RSAKeyParameters)pubKey;
    bcpgKey=new RSAPublicBCPGKey(rK.getModulus(),rK.getExponent());
  }
 else   if (pubKey instanceof DSAPublicKeyParameters) {
    DSAPublicKeyParameters dK=(DSAPublicKeyParameters)pubKey;
    DSAParameters dP=dK.getParameters();
    bcpgKey=new DSAPublicBCPGKey(dP.getP(),dP.getQ(),dP.getG(),dK.getY());
  }
 else   if (pubKey instanceof ElGamalPublicKeyParameters) {
    ElGamalPublicKeyParameters eK=(ElGamalPublicKeyParameters)pubKey;
    ElGamalParameters eS=eK.getParameters();
    bcpgKey=new ElGamalPublicBCPGKey(eS.getP(),eS.getG(),eK.getY());
  }
 else   if (pubKey instanceof ECPublicKeyParameters) {
    SubjectPublicKeyInfo keyInfo;
    try {
      keyInfo=SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(pubKey);
    }
 catch (    IOException e) {
      throw new PGPException("String_Node_Str" + e.getMessage(),e);
    }
    ASN1ObjectIdentifier curveOid=ASN1ObjectIdentifier.getInstance(keyInfo.getAlgorithm().getParameters());
    X9ECParameters params=ECNamedCurveTable.getByOID(curveOid);
    ASN1OctetString key=new DEROctetString(keyInfo.getPublicKeyData().getBytes());
    X9ECPoint derQ=new X9ECPoint(params.getCurve(),key);
    if (algorithm == PGPPublicKey.ECDH) {
      PGPKdfParameters kdfParams=(PGPKdfParameters)algorithmParameters;
      if (kdfParams == null) {
        kdfParams=new PGPKdfParameters(HashAlgorithmTags.SHA256,SymmetricKeyAlgorithmTags.AES_128);
      }
      bcpgKey=new ECDHPublicBCPGKey(curveOid,derQ.getPoint(),kdfParams.getHashAlgorithm(),kdfParams.getSymmetricWrapAlgorithm());
    }
 else     if (algorithm == PGPPublicKey.ECDSA) {
      bcpgKey=new ECDSAPublicBCPGKey(curveOid,derQ.getPoint());
    }
 else {
      throw new PGPException("String_Node_Str");
    }
  }
 else {
    throw new PGPException("String_Node_Str");
  }
  return new PGPPublicKey(new PublicKeyPacket(algorithm,time,bcpgKey),new BcKeyFingerprintCalculator());
}