runtime: System.PlatformNotSupportedException: Algorithm 'RC2' is not supported on this platform.

Description

I’m trying to convert my Xamarin App into new .NET MAUI.

This works in Xamarin:

string path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + “/cert_with_key.pfx”; byte[] rawData= File.ReadAllBytes(path); X509Certificate2 cert = new X509Certificate2(rawData, privKeyPSW); ----->this throw the following error

{System.Security.Cryptography.CryptographicException: The certificate data cannot be read with the provided password, the password may be incorrect. —> System.PlatformNotSupportedException: Algorithm ‘RC2’ is not supported on this platform.

Steps to Reproduce

  1. Create a File > New .NET MAUI App
  2. Create a pfx file with this name cert_with_key.pfx in application folder with a password
  3. And use the code in the description
  4. Excute on Android Device

Link to public reproduction project repository

no

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android from 10

Did you find any workaround?

No

Relevant log output

{System.Security.Cryptography.CryptographicException: The certificate data cannot be read with the provided password, the password may be incorrect.
 ---> System.PlatformNotSupportedException: Algorithm 'RC2' is not supported on this platform.
   at System.Security.Cryptography.PasswordBasedEncryption.CreateRC2()
   at System.Security.Cryptography.PasswordBasedEncryption.Decrypt(AlgorithmIdentifierAsn& algorithmIdentifier, ReadOnlySpan`1 password, ReadOnlySpan`1 passwordBytes, ReadOnlySpan`1 encryptedData, Span`1 destination)
   at System.Security.Cryptography.X509Certificates.UnixPkcs12Reader.DecryptSafeContents(ReadOnlySpan`1 password, ContentInfoAsn& safeContentsAsn)
   at System.Security.Cryptography.X509Certificates.UnixPkcs12Reader.DecryptAndProcessSafeContents(ReadOnlySpan`1 password, CertBagAsn[]& certBags, AttributeAsn[][]& certBagAttrs, Int32& certBagIdx, SafeBagAsn[]& keyBags, Int32& keyBagIdx)
   at System.Security.Cryptography.X509Certificates.UnixPkcs12Reader.Decrypt(ReadOnlySpan`1 password, ReadOnlyMemory`1 authSafeContents)
   at System.Security.Cryptography.X509Certificates.UnixPkcs12Reader.VerifyAndDecrypt(ReadOnlySpan`1 password, ReadOnlyMemory`1 authSafeContents)
   at System.Security.Cryptography.X509Certificates.UnixPkcs12Reader.Decrypt(SafePasswordHandle password, Boolean ephemeralSpecified)
   --- End of inner exception stack trace ---
   at System.Security.Cryptography.X509Certificates.UnixPkcs12Reader.Decrypt(SafePasswordHandle password, Boolean ephemeralSpecified)
   at System.Security.Cryptography.X509Certificates.AndroidCertificatePal.ReadPkcs12(ReadOnlySpan`1 rawData, SafePasswordHandle password, Boolean ephemeralSpecified)
   at System.Security.Cryptography.X509Certificates.AndroidCertificatePal.FromBlob(ReadOnlySpan`1 rawData, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags)
   at System.Security.Cryptography.X509Certificates.CertificatePal.FromBlob(ReadOnlySpan`1 rawData, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags)
   at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(Byte[] rawData, String password, X509KeyStorageFlags keyStorageFlags)
   at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(Byte[] rawData, String password)
   at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData, String password)

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 20 (12 by maintainers)

Most upvoted comments

Thank you @JairJr, do you use some plugin like BouncyCastle? or Portable Bouncy Castle?

Might be worth a try.

It seems that’s the reason RC2 is no longer working with the Android API’s. Looks like they had a bouncy castle dependency and dropped it completely.

Since there’s nothing we can do on our side, I’m going to close this issue.