通过C#来加载X509格式证书文件并生成RSA对象

private static RSACryptoServiceProvider GetPrivateKey(string priKeyFile, string keyPwd)
{
    var pc = new X509Certificate2(priKeyFile, keyPwd, X509KeyStorageFlags.MachineKeySet);
    return (RSACryptoServiceProvider) pc.PrivateKey;
}

private static RSACryptoServiceProvider GetPublicKey(string pubKeyFile)
{
    var pc = new X509Certificate2(pubKeyFile);
    return (RSACryptoServiceProvider) pc.PublicKey.Key;
}

*.cer格式公钥证书及*.pfx格式私钥证书

posted @ 2016-09-26 16:30  FrankYou  阅读(5136)  评论(0编辑  收藏  举报