title: Generating PGP key ring using Bouncy Castle (C#) results in key ID FFFFFFFF
body: <p>I try to generate an RSA key pair using Bouncy Castle for C#. I followed the tutorial for Java available at <a href="http://bouncycastle-pgp-cookbook.blogspot.de/2013_01_01_archive.html" rel="nofollow">http://bouncycastle-pgp-cookbook.blogspot.de/2013_01_01_archive.html</a> and create a master key and a signing key. My code looks like</p>
  
  <pre><code>IAsymmetricCipherKeyPairGenerator generator
      = GeneratorUtilities.GetKeyPairGenerator("RSA");
  generator.Init(keyRingParams.RsaParams);
  
  /* Create the master (signing-only) key. */
  PgpKeyPair masterKeyPair = new PgpKeyPair(
      PublicKeyAlgorithmTag.RsaSign,
      generator.GenerateKeyPair(),
      DateTime.UtcNow);
  Debug.WriteLine("Generated master key with ID "
      + masterKeyPair.KeyId.ToString("X"));
  
  PgpSignatureSubpacketGenerator masterSubpckGen
      = new PgpSignatureSubpacketGenerator();
  masterSubpckGen.SetKeyFlags(false, PgpKeyFlags.CanSign
      | PgpKeyFlags.CanCertify);
  masterSubpckGen.SetPreferredSymmetricAlgorithms(false,
      (from a in keyRingParams.SymmetricAlgorithms
          where a.IsSelected
          select (int) a.Value).ToArray());
  masterSubpckGen.SetPreferredHashAlgorithms(false,
      (from a in keyRingParams.HashAlgorithms
          where a.IsSelected
          select (int) a.Value).ToArray());
  
  /* Create a signing and encryption key for daily use. */
  PgpKeyPair encKeyPair = new PgpKeyPair(
      PublicKeyAlgorithmTag.RsaGeneral,
      generator.GenerateKeyPair(),
      DateTime.UtcNow);
  Debug.WriteLine("Generated encryption key with ID "
      + encKeyPair.KeyId.ToString("X"));
  
  PgpSignatureSubpacketGenerator encSubpckGen
      = new PgpSignatureSubpacketGenerator();
  encSubpckGen.SetKeyFlags(false, PgpKeyFlags.CanEncryptCommunications
      | PgpKeyFlags.CanEncryptStorage);
  masterSubpckGen.SetPreferredSymmetricAlgorithms(false,
      (from a in keyRingParams.SymmetricAlgorithms
          where a.IsSelected
          select (int) a.Value).ToArray());
  masterSubpckGen.SetPreferredHashAlgorithms(false,
      (from a in keyRingParams.HashAlgorithms
          where a.IsSelected
          select (int) a.Value).ToArray());
  
  /* Create the key ring. */
  PgpKeyRingGenerator keyRingGen = new PgpKeyRingGenerator(
      PgpSignature.DefaultCertification,
      masterKeyPair,
      keyRingParams.Identity,
      keyRingParams.PrivateKeyEncryptionAlgorithm.Value,
      keyRingParams.GetPassword(),
      true,
      masterSubpckGen.Generate(),
      null,
      new SecureRandom());
  
  /* Add encryption subkey. */
  keyRingGen.AddSubKey(encKeyPair, encSubpckGen.Generate(), null);
  
  /* Generate the key ring. */
  keyRingGen.GenerateSecretKeyRing();
  </code></pre>
  
  <p>The code works so far, the debug output also prints meaningful key IDs. However, if I save the private key to a file and import it to GnuPG, it shows <code>sec      0s/FFFFFFFF 2013-07-30</code> for the master key. The encryption key is OK.</p>
  
  <p>Edit: <code>gpg --list-packet</code> shows</p>
  
  <pre><code>:secret key packet:
          version 4, algo 3, created 1375205303, expires 0
          unknown algorithm 3
  </code></pre>
  
  <p>Algorithm 3 is <code>PublicKeyAlgorithmTag.RsaSign</code>, which I assume is OK for a master key (the Java sample does that, too), but GnuPG does not like this...</p>
  
  <p>What am I doing wrong?</p>
  
  <p>Thanks in advance,
  Christoph</p>