将RSA公钥和私钥导入VB.NET

时间:2015-02-20 22:36:27

标签: vb.net key rsa

我对RSA加密有点新意。我使用PGPfreeware 6.5.8创建了一个RSA密钥对,我正在编写一个VB.NET代码,用于加密和解密XML文件中的字段。我导出了包含公钥和私钥的RSA密钥,我得到了.asc扩展名(For ASCII)的文件。我得到了这种格式的公钥和私钥:

-----BEGIN PGP PRIVATE KEY BLOCK-----
Version: PGPfreeware 6.5.8 for non-commercial use <http://www.pgp.com>

lQOfA1Tnk1QAAAEIANl3u0UiHAEShaaHRqqL+5nFsrJSHSsRWnPbYjbT7CeJro6Z
Yiwd897w2UW5e7f9sBE6wQBg5qxPodP/kE+70xOlNcCRoV2NexoO8ldDWsm6Sb8s
nB5Paa3cvjC76NZL8E9lGkaPYICJIzN2LtDsgYtYzNnpL4hJ9lHBjeYFr8PGgkQO
7gnVSCGJvDfo9Ov+mmq94aS8eIfMSkyy58zGU4qifbiNF8vBDYhB03H+sdmEDhGx
WH+oWp5LWOgIytW/ZKRuALU75omyeBhVz+nVxziXl1cQR1cahG3fGpaEZDs3SW2t
GDnL2T/z0ED+HVh86yId2+pFimkWlmMiQqqSOK0ABREBod8mktdzj5IH+PvIArUB
4zUTzhvO9WOW5nE62EWDaOiMvofdTDqNHwNkL8JZvSt09wwT24KOhMQqJOgjI0xF
Wl6abL4gsiQ8f7Dy7Fj5+rgepsd9lrAbDPvk5xsy47YMsoPClADfmzWUdaFrLZYc
ZYDPIYwLuzwhkl7qr14WGBY3OKRP9e/oU2oD2AtF2M0tMvaaaE5qiR1+HtpmNy1s
N/fZzUOUOyjypKXWIBHG6gEfm8MfxkYxECnPkHWWjwWCKe4lFw2hnKKhjjC64kSH
asqkZDQ5OekT+icb5H4J94pcn9L4xbwQGpIenPuCYbU2WiJPKhdt1w9C9EsWavpG
4lDvjPxFC8jlZQQALns8/MdcoX8eoOZvse3Iy++lQGNix6CzaKbet4mBRHMCyUD/
HTt0BQVi7fF4u9/edXuQvN/DIZxhwxYoiZB2P18zhkqyhXPUUQMEeDuf4KazaV/0
TfPJ9PC+9WwL4jfrNw1DywKQB1nhz/P54leQbvXdp4/4hlXQxXIj9Jjriz4EANlD
I/WFS87GZtTKJdIQbu7CtyQIF1Ykob1vgPy+/1wJhJMc/O6S+WHjl7WODNc0qIF/
l1CjM2d6h3xU4m2Ng51tfrb8D9uD05B7vVOGRaEqh8lpayjXn9PAOlmqAXhDZMjr
caxjT3ncdxiJzjBFuaLcIs9d8r5amvtzFMnpB2BGA/20c0+XulFlksPa9lB8frft
r1APvYNaLm5VfqweXl8VS6Zw1KEy19RbhxpOYJ1GfrdptsqG8SvXhfzGLILzHos0
QUCYBr7ymlj5cC3CClhFpTi2E5yQntuOlUtk5JTznaG3RZxUlQy/hsU3Js/q18UH
KDvKMMiW/BPQAdpOJZcVcEt7tCFBbmFzIE4uIE1vdXNhIDxhbW91c2FAbWVkY29y
LmNvbT4=
=pxF6
-----END PGP PRIVATE KEY BLOCK-----
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: PGPfreeware 6.5.8 for non-commercial use <http://www.pgp.com>

mQENA1Tnk1QAAAEIANl3u0UiHAEShaaHRqqL+5nFsrJSHSsRWnPbYjbT7CeJro6Z
Yiwd897w2UW5e7f9sBE6wQBg5qxPodP/kE+70xOlNcCRoV2NexoO8ldDWsm6Sb8s
nB5Paa3cvjC76NZL8E9lGkaPYICJIzN2LtDsgYtYzNnpL4hJ9lHBjeYFr8PGgkQO
7gnVSCGJvDfo9Ov+mmq94aS8eIfMSkyy58zGU4qifbiNF8vBDYhB03H+sdmEDhGx
WH+oWp5LWOgIytW/ZKRuALU75omyeBhVz+nVxziXl1cQR1cahG3fGpaEZDs3SW2t
GDnL2T/z0ED+HVh86yId2+pFimkWlmMiQqqSOK0ABRG0IUFuYXMgTi4gTW91c2Eg
PGFtb3VzYUBtZWRjb3IuY29tPokBFQMFEFTnk1SWYyJCqpI4rQEBZJwH/i+HfaZk
dnhPFNVZu/Noy6z1EMHylQSGODMBWZskPOGmhfnzQT9Ex9qbPfpdD9XTMEYRiR2j
iqkMpZOHlnVuk9dxCFM0q+QvZ6AYFo8OVQSiO4FbQ4evD/qBp4IxiSgKV0+20e4y
XKZbdiIue8wXjzXEv/DB8wmNZLL114gwYrmYPPdBtvqyKuTNjubu3jFX6WYrC4F7
Yi713XwnjS810YIeVo00dUOEnyBzDhLaRDLuWB4cQw3dpD7iRf0xz4yIWsCjRFj1
p7ZDpjfSVi6rDWBWgb2Vlh0jcY3wXuE5EZAAgPzBAmHWFxmegDfeIkpN243BWjrf
w3cqJLJvkMxU4DE=
=ds/P
-----END PGP PUBLIC KEY BLOCK-----

当我尝试将公钥和私钥传递给我的RSACryptoServiceProvider对象时,我发现这些密钥的形式不适用于.NET来处理它们; .NET仅处理XML公钥和私钥。我通过互联网搜索,发现这种格式的密钥是使用Base64转换原始文本的结果,所以我尝试将它们转换回普通文本而不是Base64文本,这样我就可以 - 将它们导入我的对象,但我得到一个FormatException说:Base-64字符串中的无效字符。我究竟做错了什么?以及我如何才能使我的文件作为我的RSA对象的公钥和私钥?

谢谢。

0 个答案:

没有答案