CSharp-easy-RSA-PEM icon indicating copy to clipboard operation
CSharp-easy-RSA-PEM copied to clipboard

Getting System.NullReferenceException

Open jhakasjk opened this issue 7 years ago • 2 comments

I'm getting below exception while trying to decrypt the string. "System.NullReferenceException: Object reference not set to an instance of an object.\r\n at CoreEntities.Classes.Utility.RSADecrypt(String input)\r\n at WebAPI.Attributes.ApiAuthorizeAttribute.Authorize(HttpActionContext actionContext)"

Code:-

public static string RSADecrypt(string input)
        {
            try
            {
                string priv = File.ReadAllText(HostingEnvironment.MapPath("~/Certificates/consumer.pem"));
                RSACryptoServiceProvider privc = Crypto.DecodeRsaPrivateKey(priv);
                return Crypto.DecryptString(input, privc);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

It is only coming when i deploy my application on windows server 2012 although it's working fine on local machine on iis and via visual studio 2015.

How to fix this?

jhakasjk avatar Aug 04 '17 07:08 jhakasjk

I am also facing the same issue . @jhakasjk , did you find solution to this?

solo-developer avatar Aug 28 '22 08:08 solo-developer

Found a solution : https://stackoverflow.com/questions/45503830/getting-exception-on-server-when-using-rsa-via-csharp-easy-rsa-pem

solo-developer avatar Aug 29 '22 11:08 solo-developer