Eduardo Guerra
Eduardo Guerra

Reputation: 21

Failure of the DecryptKey method of BouncyCastle in Azure Web application

I have a MVC .Net 4.6.2 Web application that uses the following code to get an RSACryptoServiceProvider:

    public static RSACryptoServiceProvider GetKey(byte[] key, string pass)
    {
        Org.BouncyCastle.Crypto.AsymmetricKeyParameter asp = Org.BouncyCastle.Security.PrivateKeyFactory.DecryptKey(pass.ToCharArray(), key);
        var rsa = DotNetUtilities.ToRSA((RsaPrivateCrtKeyParameters)asp) as RSACryptoServiceProvider;
        return rsa;
    }

On my Web server using IIS, it works correctly.

When I publish in the Azure portal the DecryptKey method returns the following error:

The system can not find the specified file.

Any ideas?

Upvotes: 1

Views: 310

Answers (1)

Eduardo Guerra
Eduardo Guerra

Reputation: 21

In this operation:

var asp = Org.BouncyCastle.Security.PrivateKeyFactory.DecryptKey(pass.ToCharArray(), key);

BouncyCastle required access to the server's KeyChange, the solution is to add a Configuration setting in Azure Portal.

The following can be added in the Advanced Edit for the Application Settings:

  {
    "name": "WEBSITE_LOAD_CERTIFICATES",
    "value": "1",
    "slotSetting": false
  }

Or you can add it using the standard Settings editor like in the below screenshots: Parameter Azure Portal

Application Setting

Upvotes: 1

Related Questions