Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

problem generating pgp keys?

I'm using RSACryptoServiceProvider I've generated public key and private key. The keys generated by it are in the following format:

Public key:

<RSAKeyValue>
    <Modulus>m9bAoh2...eGNKYs=</Modulus>
    <Exponent>AQAB</Exponent>
</RSAKeyValue> 

Private key:

<RSAKeyValue>
    <Modulus>m9bAo...ZAIeGNKYs=</Modulus>
    <Exponent>AQAB</Exponent>
    <P>xGj/UcXs...R1lmeVQ==</P>
    <Q>yx6e18aP...GXzXIXw==</Q>
    <DP>NyxvnJ...1xAsEyQ==</DP>
    <DQ>La17Jycd...FhApEqwznQ==</DQ>
    <InverseQ>JrG7WCT...Hp3OWA==</InverseQ>
    <D>RdWsOFn....KL699Vh6HK0=</D>
</RSAKeyValue>

but using PGP Desktop i've generated keys like this -

Public key:

mQCNBEoOlp8BBACi/3EvBZ83ZduvG6YHu5F0P7Z3xOnpIsaPvTk0q+dnjwDUa5sU 
lEFbUZgDXSz7ZRhyiNqUOy+IG3ghPxpiKGBtldVpi33qaFCCEBiqsxRRpVCLgTUK 
HP2kH5ysrlFWkxTo 
=a4t9 

Private key:

lQHgBEoOlp8BBACi/3EvBZ83ZduvG6YHu5F0P7Z3xOnpIsaPvTk0q+dnjwDUa5sU 
lEFbUZgDXSz7ZRhyiNqUOy+IG3ghPxpiKGBtldVpi33qaFCCEBiqsxRRpVCLgTUK 
waBnEitQti3XgUUEZnz/rnXcQVM0QFBe6H5x8fMDUw== 
=CVPD 

So when I'm passing the keys generated by PGP Desktop it is able to do encryption and decryption perfectly but when im passing the keys generated by RSACryptoServiceProvider I'm not able to encrypt and decrypt?

Can anyone please tell me how to generate keys in the pattern generated by PGP?

like image 983
pavankumar Avatar asked Dec 20 '25 02:12

pavankumar


1 Answers

using the bouncycastle c# library this is how i generate key pairs.



public void GenerateKey(string username, string password, string keyStoreUrl)
        {
            IAsymmetricCipherKeyPairGenerator kpg = new RsaKeyPairGenerator();
            kpg.Init(new RsaKeyGenerationParameters(BigInteger.ValueOf(0x13), new SecureRandom(), 1024, 8));
            AsymmetricCipherKeyPair kp = kpg.GenerateKeyPair();

            FileStream out1 = new FileInfo(string.Format("{0}secret.asc", keyStoreUrl)).OpenWrite();
            FileStream out2 = new FileInfo(string.Format("{0}pub.asc", keyStoreUrl)).OpenWrite();

            ExportKeyPair(out1, out2, kp.Public, kp.Private, username, password.ToCharArray(), true);

        }

private static void ExportKeyPair(
            Stream secretOut,
            Stream publicOut,
            AsymmetricKeyParameter publicKey,
            AsymmetricKeyParameter privateKey,
            string identity,
            char[] passPhrase,
            bool armor)
        {
            if (armor)
            {
                secretOut = new ArmoredOutputStream(secretOut);
            }

            PgpSecretKey secretKey = new PgpSecretKey(
                PgpSignature.DefaultCertification,
                PublicKeyAlgorithmTag.RsaGeneral,
                publicKey,
                privateKey,
                DateTime.Now,
                identity,
                SymmetricKeyAlgorithmTag.Cast5,
                passPhrase,
                null,
                null,
                new SecureRandom()
                //                ,"BC"
                );

            secretKey.Encode(secretOut);

            secretOut.Close();

            if (armor)
            {
                publicOut = new ArmoredOutputStream(publicOut);
            }

            PgpPublicKey key = secretKey.PublicKey;

            key.Encode(publicOut);

            publicOut.Close();
        }

and it generate private and public keys in armored ASCII format such as.

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: BCPG v1.32

mIsEShU7ywEEAKtxKTtGTyUaVxFuWBpziA2l7qDKhe6jznre3DMPuzDnN4Ax573a
7s/bPOkzkK9tEUGFw+BW6F4DkKydv8SQfSN5Vvc0RFMha8X1E8jki1oXTIPA8bKK
dg8ZewZt8+Zwpt5IPAkIydmxDhMjwd71ay3p1ypOfROFPOfc2dBPx/0JAAUTtAdo
YW1zbWFuiJwEEAECAAYFAkoVdAsACgkQEz/ESPB1tojuIQP8CjAzJx8PoIN33pxQ
AfGF+fMCZx8/m7dDBE113aiio25BCvNKOpFwye2UK4ioKN70k24pzkyi8AZO22/s
u6GL7XEiiBZLPynBxJR4A7PzvD3KNqdQUqesu9IkPFyXz3UFH3clR0hnZtZtgnbk
L9dvj5RYVuGiS3Dcf1zoLMOiCdc=
=dFfG
-----END PGP PUBLIC KEY BLOCK-----
like image 197
Emmanuel Avatar answered Dec 22 '25 17:12

Emmanuel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!