• 虚拟主机用RSA生成公钥时提示找不到文件
  • 2018/12/16 13:00:27  浏览次数:904
  • 1、问题:编写webservice用以下方法生成公钥时,本地调试成功,但上传到虚拟空间后,提示找不到文件。

    [WebMethod]
    public string ReturnPublickKey()
    {
        try
        {

            RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();

            string str_Public_Key = Convert.ToBase64String(RSA.ExportCspBlob(false));
            string str_Private_Key = Convert.ToBase64String(RSA.ExportCspBlob(true));
            return str_Public_Key;
        }
        catch (CryptographicException e)
        {
            Console.WriteLine(e.Message);
            return "no key";
        }
    }

    2、解决方法如下:

    [WebMethod]
    public string ReturnPublickKey()
    {
        try
        {
            CspParameters RSAParams = new CspParameters();
            RSAParams.Flags = CspProviderFlags.UseMachineKeyStore;

            RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(1024, RSAParams);

            string str_Public_Key = Convert.ToBase64String(RSA.ExportCspBlob(false));
            string str_Private_Key = Convert.ToBase64String(RSA.ExportCspBlob(true));
            return str_Public_Key;
        }
        catch (CryptographicException e)
        {
            Console.WriteLine(e.Message);
            return "no key";
        }
    }

     


  • 分享:0
  • CopyRight 2012-2013 河北廊坊天智软件
  • 冀ICP备09044623号