• 虛擬主機用RSA生成公鑰時提示找不到文件
  • 2018/12/16 13:00:27  瀏覽次數:237
  • 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
找几个欢乐麻将豆商