BouncyCastle PgpSecretKeyRing errors while reading text with Pgp Private Key Block

36 views Asked by At

I have a C# project where I'm trying to write a unit test. The test should read a block of text containing Pgp Private Key Block info. I eventually want to convert the PGP info into RSA parameters, but I'm running into other problems already.

Here is an abbreviated version of my code:

var myKeyBlock = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n\n...\n-----END PGP PRIVATE KEY BLOCK-----\n";

PgpSecretKeyRing myKeyRing = GetSecretKeyRing(myKeyBlock);

private static PgpSecretKeyRing GetSecretKeyRing(string keyBlock)
{
    try
    {
        using (Stream keyStream = new MemoryStream(Encoding.UTF8.GetBytes(keyBlock)))
        {
            PgpSecretKeyRing secretKeyRing = new PgpSecretKeyRing(keyStream);
            return secretKeyRing;
        }
    }
    catch (PgpException ex)
    {
        ...
    }
}

I keep receiving variations of the following error:

System.IO.IOException : secret key ring doesn't start with secret key tag: tag 0xB

I've tried different values for myKeyBlock (where ... always contains what-I-believe-to-be valid info, but nothing has worked yet.

0

There are 0 answers