1

I'm trying to find the equivalent from UWP

 var rsa = AsymmetricKeyAlgorithmProvider.OpenAlgorithm(AsymmetricAlgorithmNames.RsaPkcs1);
 var keyPair = rsa.CreateKeyPair(2048);
 var publicKey = keyPair.ExportPublicKey();
 var publicKeyStr = Convert.ToBase64String(publicKey.ToArray());

to .net standard 2.0 without any success:

var providerTYpe = new CspParameters() { ProviderType = 1 };
var rsaProvider = new RSACryptoServiceProvider(2048, providerType);
string publicKey = Convert.ToBase64String(rsaProvider.ExportCspBlob(false));

or following the answer in here C# Export Private/Public RSA key from RSACryptoServiceProvider to PEM string

var providerType = new CspParameters() { ProviderType = 1 };
var rsaProvider = new RSACryptoServiceProvider(2048, providerType);
var publicKey = PemWritter.ExportPublicKeyToPEMFormat(rsaProvider);

The code from the UWP is working fine, and is generating a proper set of keys and I can extract the PublicKey easily to PEM format.

I tried this solution also http://www.japf.fr/2013/05/rsa-cryptography-between-a-winrt-and-a-dotnet-app/ but in that link they are forcing UWP to use Capi1PublicKey which is not available I think in the .net standard implementation. The public key from the UWP implementation is being accepted by the server, but not the .net standard one.

Fritjof Berggren
  • 3,178
  • 5
  • 35
  • 57

0 Answers0