In MAUI project targeting iOS release with MtouchLink = SdkOnly we are seeing the error "PlatformNotSupported" for the execution of PCLCrypto.SymmetricKeyAlgorithmProvider.GetAlgorithm() at PCLCrypto.SymmetricKeyAlgorithmProvider.CreateSymmetricKey(Byte[] keyMaterial) .
When we set the MtouchLink option to None in debug it works fine. As in release mode we need MtouchLink = SdkOnly so it gives the above error when i try to login.
We dont see this issue in our Android release builds of the same project.
We were using 2.0.147 of PCLCrypto and Updated it to latest version i.e - 2.1.40-alpha but still it didn't fixed the issue. This used to work fine in Xamarin.forms but after migration it doesn't work on MAUI IOS release.
Steps to Reproduce
public static string EncryptAesPwd(string data)
{
byte[] key = CreateDerivedKey();
ISymmetricKeyAlgorithmProvider aes = WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesCbcPkcs7);
ICryptographicKey symetricKey = aes.CreateSymmetricKey(key);
var bytes = WinRTCrypto.CryptographicEngine.Encrypt(symetricKey, Encoding.UTF8.GetBytes(data));
return Convert.ToBase64String(bytes, 0, bytes.Length);
}
private static byte[] CreateDerivedKey(int keyLengthInBytes = 32, int iterations = 1000)
{
string password = AppConfiguration.AuthSecretKey;
byte[] salt = Convert.FromBase64String(AppConfiguration.AuthSecretSalt);
byte[] key = NetFxCrypto.DeriveBytes.GetBytes(password, salt, iterations, keyLengthInBytes, System.Security.Cryptography.HashAlgorithmName.SHA1);
return key;
}