2009-05-21 123 views
2

我正在使用RSACryptoServiceProvider我已經生成了公鑰和私鑰。由它生成的關鍵是採用以下格式:生成pgp鍵的問題?

公鑰:

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

私鑰:

<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> 

但使用PGP桌面我已經生成的密鑰這樣的 -

公鑰:

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

私鑰:

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

所以,當我路過PGP桌面生成的密鑰是能夠做到的加密和解密完美,但是當路過的RSACryptoServiceProvider生成的密鑰IM我不能來加密和解密?

任何人都可以請告訴我如何生成由PGP生成的模式的密鑰?

+0

Backrub:https://security.stackexchange.com/q/1750/2379 – Pacerier 2018-01-31 14:58:34

回答

5

RSA和PGP是不同的。

你基本上要問的是如何在柴油上運行我的汽油車?答案是你不能。


您應該看看PGP CommandLine - 它允許您從命令行執行PGP命令。

8

使用bouncycastle c#庫這是我如何生成密鑰對。



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(); 
     } 

它會生成鎧甲ASCII格式的私鑰和公鑰,例如。

 
-----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----- 
1

感謝您的好方法,是faffing各地的網絡爲他們,因爲很長一段時間,

一些修正壽...

通話結束後,以

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

請致電

out1.Close(); 
out2.Close(); 

從上述常規

-----BEGIN PGP PRIVATE KEY BLOCK----- 
Version: BCPG C# v1.6.1.0 

lQHqBEvhYOcBBACa5HjZ14ULRvZLKj+rwscQh63Zd9rnfZmVKN5fNsK+ocxxV8rc 
TWa6P3knIWCra1lqZ1onNtM8tL1XRuK9pagu7XPjjHUR37ajYv/e0/w9IHlOBtM4 
1T3oMM48FBH5WGZswOQnTCHoHpZilx7zeJgcyoUayM9uaWGWVLb6PqAE2QAFE/8D 
AwL4BEE4Y+mD6GB0ctnbN4tZuctydODYJUNOK3p+UdgEh5rj5nOelB5h3kqFWdwq 
8F3EBxB4guRnLOxIeSjzvFoFpqb4QSrM4brdisaHoK0qgrsyCaQhdepVlz662hSD 
5bxJPQqmJ4c9X7x6tTMwDAseoz+VUK9U91iN9jv72hp2dXJYjJvBbkTX9euz2i4P 
HrlLV2DuOeGWipsb+sIOuYqpZoK5aMq5AAGTTmmApYam/+0d2lXTt+Cw0FkoN1U+ 
CWriVFE+x58/MmpqKttlrHyp/c7aRmdxeKheY7QAnKPmTRFZAu6HR/DnLSya6+Qz 
MqsYBZAocDs7Bg9U6N79Ynl7mkChoVR4ZwJE/OXgHDRSYlcBwT++frHI06cn1l8t 
f0CWU/Z6EuYj/rmgL/v5ln7EQ2H+SRypPxYJKK8dTcu2uk5Ev1x4EOQ2nF1BxBB1 
CceSVEimc2TDcVj0K7QIc3BhcmVraDOInAQQAQIABgUCS+FS1wAKCRBHXl7hbFhY 
BLInA/9TPwmivxofs7/y4xmrl0X+Ruish0l+KC45/MQGU1bT2MYCR5jefyaUIHMK 
gH8bX4DHobBFxtkTXoTgpZmm5JNHGiSQoOXqW7iqHOkp6q6rkwV9BYvfsbjMsfAB 
bV7l29CMoMDj1qB3k9CJDP4MuorEI5Qx30x07Mm2+uwcYC2+Ag== 
=jh9t 
-----END PGP PRIVATE KEY BLOCK----- 

感謝產生再次用於上述方法的樣品的私鑰。

-----BEGIN PGP PUBLIC KEY BLOCK----- 
Version: BCPG C# v1.6.1.0 

mIsES+Fg5wEEAJrkeNnXhQtG9ksqP6vCxxCHrdl32ud9mZUo3l82wr6hzHFXytxN 
Zro/eSchYKtrWWpnWic20zy0vVdG4r2lqC7tc+OMdRHftqNi/97T/D0geU4G0zjV 
PegwzjwUEflYZmzA5CdMIegelmKXHvN4mBzKhRrIz25pYZZUtvo+oATZAAUTtAhz 
cGFyZWtoM4icBBABAgAGBQJL4VLXAAoJEEdeXuFsWFgEsicD/1M/CaK/Gh+zv/Lj 
GauXRf5G6KyHSX4oLjn8xAZTVtPYxgJHmN5/JpQgcwqAfxtfgMehsEXG2RNehOCl 
mabkk0caJJCg5epbuKoc6SnqrquTBX0Fi9+xuMyx8AFtXuXb0IygwOPWoHeT0IkM 
/gy6isQjlDHfTHTsybb67BxgLb4C 
=ZyOZ 
-----END PGP PUBLIC KEY BLOCK-----