Seeing a "Synchronous reads are not supported" error in the inputStream.Read(buffer) for the following code:
public static void FileDecrypt(IFileEntry file, string newFileName, string key){ FileStream fsCrypt = new(fileName, FileMode.Create); byte[] iv = new byte[16]; using (Aes aes = Aes.Create()) { aes.Key = Encoding.UTF8.GetBytes(key); aes.IV = iv; ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, aes.IV); byte[] buffer = new byte[MAX_BYTES]; int read; using Stream inputStream = file.OpenReadStream(); try { // ********* Fails on this READ with Unsupported ****** while ((read = inputStream.Read(buffer)) > 0) { byte[] result = decryptor.TransformFinalBlock(buffer, 0, read); fsCrypt.Write(result, 0, read); } } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } }}What is puzzling, is the inputStream.Read(buffer) WORKS for the following code:
public static void FileEncrypt(IFileEntry file, string newFileName, string key){ FileStream fsCrypt = new(fileName, FileMode.Create); byte[] iv = new byte[16]; using (Aes aes = Aes.Create()) { aes.Key = Encoding.UTF8.GetBytes(key); aes.IV = iv; ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV); // Write the results in 1 megabyte chunks byte[] buffer = new byte[MAX_BYTES]; int read; using CryptoStream cryptoStream = new CryptoStream((Stream)fsCrypt, encryptor, CryptoStreamMode.Write); using Stream inputStream = file.OpenReadStream(); try { // WORKS here! while ((read = inputStream.Read(buffer)) > 0) { cryptoStream.Write(buffer, 0, read); } } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } }}I am sure it is probably something simple, but I can't see it. I am using the BlazoriseIFileEntry file, but I also tried the IBrowserFile construct from standard file upload with the same result. Trying to buffer the input into the decryption because I think the file sizes could get large.I also tried the ReadAsync() method but it simply hits that line and then never returns.