Program: 8404
Project: 8404
Buggy source:
/** 
 * Creates new secret key.
 * @param algorithmChoice
 * @param keySize
 * @param passPhrase
 * @param isMasterKey
 * @return
 * @throws NoSuchAlgorithmException
 * @throws PGPException
 * @throws NoSuchProviderException
 * @throws PgpGeneralException
 * @throws InvalidAlgorithmParameterException
 */
public PGPSecretKey createKey(int algorithmChoice,int keySize,String passPhrase,boolean isMasterKey) throws NoSuchAlgorithmException, PGPException, NoSuchProviderException, PgpGeneralException, InvalidAlgorithmParameterException {
  if (keySize < 512) {
    throw new PgpGeneralException(mContext.getString(R.string.error_key_size_minimum512bit));
  }
  if (passPhrase == null) {
    passPhrase="String_Node_Str";
  }
  int algorithm=0;
  KeyPairGenerator keyGen=null;
switch (algorithmChoice) {
case Id.choice.algorithm.dsa:
{
      keyGen=KeyPairGenerator.getInstance("String_Node_Str",Constants.BOUNCY_CASTLE_PROVIDER_NAME);
      keyGen.initialize(keySize,new SecureRandom());
      algorithm=PGPPublicKey.DSA;
      break;
    }
case Id.choice.algorithm.elgamal:
{
    if (isMasterKey) {
      throw new PgpGeneralException(mContext.getString(R.string.error_master_key_must_not_be_el_gamal));
    }
    keyGen=KeyPairGenerator.getInstance("String_Node_Str",Constants.BOUNCY_CASTLE_PROVIDER_NAME);
    BigInteger p=Primes.getBestPrime(keySize);
    BigInteger g=new BigInteger("String_Node_Str");
    ElGamalParameterSpec elParams=new ElGamalParameterSpec(p,g);
    keyGen.initialize(elParams);
    algorithm=PGPPublicKey.ELGAMAL_ENCRYPT;
    break;
  }
case Id.choice.algorithm.rsa:
{
  keyGen=KeyPairGenerator.getInstance("String_Node_Str",Constants.BOUNCY_CASTLE_PROVIDER_NAME);
  keyGen.initialize(keySize,new SecureRandom());
  algorithm=PGPPublicKey.RSA_GENERAL;
  break;
}
default :
{
throw new PgpGeneralException(mContext.getString(R.string.error_unknown_algorithm_choice));
}
}
PGPKeyPair keyPair=new JcaPGPKeyPair(algorithm,keyGen.generateKeyPair(),new Date());
PGPDigestCalculator sha1Calc=new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1);
PBESecretKeyEncryptor keyEncryptor=new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.CAST5,sha1Calc).setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(passPhrase.toCharArray());
PGPSecretKey secKey=new PGPSecretKey(keyPair.getPrivateKey(),keyPair.getPublicKey(),sha1Calc,isMasterKey,keyEncryptor);
return secKey;
}

Fixed version (ground truth):
public PGPSecretKey createKey(int algorithmChoice,int keySize,String passPhrase,boolean isMasterKey) throws NoSuchAlgorithmException, PGPException, NoSuchProviderException, PgpGeneralException, InvalidAlgorithmParameterException {
  if (keySize < 512) {
    throw new PgpGeneralException(mContext.getString(R.string.error_key_size_minimum512bit));
  }
  if (passPhrase == null) {
    passPhrase="String_Node_Str";
  }
  int algorithm;
  KeyPairGenerator keyGen;
switch (algorithmChoice) {
case Id.choice.algorithm.dsa:
{
      keyGen=KeyPairGenerator.getInstance("String_Node_Str",Constants.BOUNCY_CASTLE_PROVIDER_NAME);
      keyGen.initialize(keySize,new SecureRandom());
      algorithm=PGPPublicKey.DSA;
      break;
    }
case Id.choice.algorithm.elgamal:
{
    if (isMasterKey) {
      throw new PgpGeneralException(mContext.getString(R.string.error_master_key_must_not_be_el_gamal));
    }
    keyGen=KeyPairGenerator.getInstance("String_Node_Str",Constants.BOUNCY_CASTLE_PROVIDER_NAME);
    BigInteger p=Primes.getBestPrime(keySize);
    BigInteger g=new BigInteger("String_Node_Str");
    ElGamalParameterSpec elParams=new ElGamalParameterSpec(p,g);
    keyGen.initialize(elParams);
    algorithm=PGPPublicKey.ELGAMAL_ENCRYPT;
    break;
  }
case Id.choice.algorithm.rsa:
{
  keyGen=KeyPairGenerator.getInstance("String_Node_Str",Constants.BOUNCY_CASTLE_PROVIDER_NAME);
  keyGen.initialize(keySize,new SecureRandom());
  algorithm=PGPPublicKey.RSA_GENERAL;
  break;
}
default :
{
throw new PgpGeneralException(mContext.getString(R.string.error_unknown_algorithm_choice));
}
}
PGPKeyPair keyPair=new JcaPGPKeyPair(algorithm,keyGen.generateKeyPair(),new Date());
PGPDigestCalculator sha1Calc=new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1);
PBESecretKeyEncryptor keyEncryptor=new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.CAST5,sha1Calc).setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(passPhrase.toCharArray());
return new PGPSecretKey(keyPair.getPrivateKey(),keyPair.getPublicKey(),sha1Calc,isMasterKey,keyEncryptor);
}