check out System.Security.Cryptography.X509Certificates.X509Certificate

解决方案 »

  1.   

    Here is a small example. You need to download WSH sdk from microsoft to get X509CertificateStore support.using System;
    using System.Security.Cryptography;
    using System.Text;
    using Microsoft.Web.Services.Security.X509;
    ......public static string decrypt(byte[] content)
    {
    X509CertificateStore store =  X509CertificateStore.CurrentUserStore( X509CertificateStore.MyStore );
    store.OpenRead();
    X509Certificate receiver = (X509Certificate)store.Certificates[0];
    string receiver_serial = receiver.GetName();
    Console.WriteLine(" name :"+receiver_serial);
    RSAParameters receiver_private = receiver.Key.ExportParameters( true );
    RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
    rsa.ImportParameters( receiver_private ); 
    byte[] cipher = rsa.Decrypt(content, false );
    string cleartext = ASCIIEncoding.ASCII.GetString(cipher);
    return cleartext;
    }
    public static byte[] encrypt(string text)
    {
    X509CertificateStore store =  X509CertificateStore.CurrentUserStore( X509CertificateStore.MyStore );
    store.OpenRead();
    X509Certificate receiver = (X509Certificate)store.Certificates[0];
    string receiver_serial = receiver.GetName();
    Console.WriteLine(" name :"+receiver_serial);
    RSAParameters receiver_public = receiver.Key.ExportParameters( false );
    RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
    rsa.ImportParameters( receiver_public ); 
    byte[] cleartext = ASCIIEncoding.ASCII.GetBytes(text);
    byte[] cipher = rsa.Encrypt( cleartext, false );
    return cipher;
    } public static void Main()
    {
    byte[] content = encrypt("hello world!");
        Console.WriteLine(decrypt(content)); 
    }
      

  2.   

    a correction:
      Should be WSE (web services enhancements)
      

  3.   

    非常感谢jennyq_zq
    我装了WSE1.0和2.0,但不知道是不是因为版本冲突(我的.NET是中文版,WSE只有英文版的),在Microsoft的命名空间里没有web?