powerbicryptographycredentialsgatewayplatform

.NET 8 Application running on linux container CNG Cryptography is not supported on this platform


I have a Blazor application in .NET8 which uses the following code to Encrypt Credentials for a PowerBI datasource given a PowerBI gateway:

credentialDetails.EncryptedConnection = "NotEncrypted"; //FOR CONNECTION
credentialDetails.EncryptionAlgorithm = "RSA-OAEP"; //FOR CREDENTIALS
GatewayPublicKey gateway_towa_key = gateway_towa.PublicKey;

Credentials need to be encrypted when the resource is private and needs an onprem gateway to operate:

Microsoft.PowerBI.Api.Extensions.AsymmetricKeyEncryptor asymmetricKeyEncryptor = new(gateway_towa_key);
credentialDetails.Credentials = asymmetricKeyEncryptor.EncodeCredentials(credentialDetails.Credentials);

The above code works just fine when the app is running on Azure Web App configured to Windows Platform and .NET8 Framework, but when it runs on a linux contain it throws the following error:

Cryptography Next Generation (CNG) is not supported on this platform

Is there any other way to do the same and work for cross platform?


Solution

  • Finnaly I was able to solve this problem by taking the code from Microsoft's github and instead of calling the method though using directive now I have created the classes in my project and it just works. I suspect that the dlls of the package (Microsoft.PowerBI.Api.Extensions) have some instruction for windows or compiled for windows, or something like this.