locked
Loading PEM/DER Key to RSACryptoServiceProvider with X509Certificate2?? RRS feed

  • Question

  • public static byte[] Encrypt(byte[] data, bool key)
        {
            RSACryptoServiceProvider rsa;
            if (key)
                //Load public key
            else
            {
                //Load private key
                X509Certificate2 Key;
                Key = new X509Certificate2("c:\\users\\Tuck\\Documents\\Modtagne filer\\rsa\\RSAPrivateKey.txt");
                rsa = (RSACryptoServiceProvider)Key.PrivateKey;
            }
            data = rsa.Encrypt(data, false);
            return data;
        }
    Private PEM Key:
    -----BEGIN RSA PRIVATE KEY-----
    MIIEogIBAAKCAQEA3XK9BWuIHIS3R6za4WU/mQ0WlsPD/ErtzSTw2ZmbhI0lyKcQ
    Ugk0aRIOaq4vTE+EpRtI6hvhH4AIm+15sWPqxpfuNR0Dvigse+BhuypFsqI+AWiL
    dj5RrPSzrLcqWgjE5zSjUG4OmxS4NJJRY9UMNaEhtqsrgrFFj4iMX07bz6Joyp85
    CHpGJhmFjPwU60OlUkGKwvs6TeQXUZlH9ypzXkNAhF4uDchTgEX7A/8yrqHzPx7/
    r2T0Lww7kp106ACdy9wXTpq5v3tmfNZbZ7K0bEB4g8Ez43Hew1P5b/tabUV4pZL0
    LkvDCA78ll8FHeuJjZA3+DKlEgyA2EWTs98VTQIDAQABAoIBAC65evCd08ZQqmtR
    KY3NUzHz9QQyojOli69xT/BZ3NqG/aXsuiDVGF3jFW+k+Q3c6Vv8+dGLuGBxH1/n
    J3oqXuswO26xhIym5Vvt6DEZpkMewH6DlImKdKlNqGuU6ja9Cu7NyHe8ARDvuj49
    cTbjSQQ3z2k/jJqy1L6ITTX+6ZpRgZd9m/Ng5O0GBcoSiUjysfLgs5m5lHWCojL+
    ppxqhsWXDM2ejIFGncGok798NNps+OkAM9EwEHcEI7qBo/UEsgXwnmlUvsyBvtq3
    7NS/znsJlOT/PfbS3i0gIac6AmA0qh86zN+uC5yl44aY+WpwPqBua6eeKkpk3xAo
    LrCRxHECgYEA/689gaRf0ihJ5WpD/cq6XLFwxuu4/CmmNjYpTwol2S3lGnq03RLZ
    FhklvMKIkhfuaOLyrHgUWaYZVr2KBUU81qwHTVEZeN6rWPeXTsfgBnpShIYYXqBN
    ePyqVDuISs44Lsi74fhSNrqai6ow6GQYlZewcdjS2zVc35G1of/cWNMCgYEA3biv
    L49okrATQfBbdl5L6hueqNc8pfrv6EKYcw5SE48fFeHCToorKpaf4kf7GemITldD
    29FFwukhyt1rJJI9Kvj6jKN49QZr3xS1d8QY0lOHnRRRLIg3x+VaD7RYOWuHbqs1
    MKyzgeKkpWq6EkuaW2ZEQwL6cvzqGsbo1CRqBV8CgYBMNqEf1q5VR3sXbkCMEvTQ
    EngqYzNFvuhzelt/2ueDQCHtbawhxa993csY4+evnICNNTDe5gAy5MbiyyasAYJr
    /uVCT61HESCEKXEpo3yMkcOtCweSlTfim3XuG7y5h5TJpT4T0mA3PhI5FWb0rnmB
    hbCrjtTzUIm5foZkno7AzwKBgD2PTXSTCKHRqUchiQNwYvt497BBMmGTLpD6DIHF
    dBxiHGti5yQPULTeZT3aZmlnYaT+raSWkhvvxqYgm+Lnh3wq7MWnjanaQpEJmujJ
    1WpwLrL6NR98IqCpmTvLAsPOiye6+WWuTZi+aKBU5Zy2yQCfgExqw0ax2f3dRD/C
    bH1ZAoGAOJ/pLNpetFyE/aaD0jBfMA6UACdutjWT4vFGmk/GwBh3/sHoMbON2c/P
    OeEM/N3/ZODOZHzXB1ALgWIjeoP2TegBfbniHf2d+j1/VRMTiYEMv3ws06YiWMLJ
    ioX2ZNntCCPlIti48TeFs0etqcHQgQ5rSLblyde3RIuRcqatQko=
    -----END RSA PRIVATE KEY-----

    Public PEM Key:
    -----BEGIN RSA PUBLIC KEY-----
    MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3XK9BWuIHIS3R6za4WU/
    mQ0WlsPD/ErtzSTw2ZmbhI0lyKcQUgk0aRIOaq4vTE+EpRtI6hvhH4AIm+15sWPq
    xpfuNR0Dvigse+BhuypFsqI+AWiLdj5RrPSzrLcqWgjE5zSjUG4OmxS4NJJRY9UM
    NaEhtqsrgrFFj4iMX07bz6Joyp85CHpGJhmFjPwU60OlUkGKwvs6TeQXUZlH9ypz
    XkNAhF4uDchTgEX7A/8yrqHzPx7/r2T0Lww7kp106ACdy9wXTpq5v3tmfNZbZ7K0
    bEB4g8Ez43Hew1P5b/tabUV4pZL0LkvDCA78ll8FHeuJjZA3+DKlEgyA2EWTs98V
    TQIDAQAB
    -----END RSA PUBLIC KEY-----


    -Tuck
    Saturday, March 13, 2010 11:33 PM

Answers

All replies