How to do a AES decryption in UWP, for a data encrypted using RijndaelManaged in .NET Framework?

Petchiammal Rajumayandi 61 Reputation points
2023-03-15T03:11:13.1566667+00:00

Hi,

My UWP app receives some data from Server. The server is developed in .NET Framework. The server side encrypts the using the RijndaelManaged as below

byte[] passwordKey = convertStringToByteArray("SharedKey");

                    using (var cryptoProvider = new RijndaelManaged())
                    using (var memoryStream = new MemoryStream())
                    using (var cryptoStream = new CryptoStream(memoryStream, cryptoProvider.CreateEncryptor(passwordKey, passwordKey), CryptoStreamMode.Write))
                    using (var writer = new StreamWriter(cryptoStream))
                    {
                        writer.Write(originalString);
                        writer.Flush();
                        cryptoStream.FlushFinalBlock();
                        writer.Flush();
                        return Convert.ToBase64String(memoryStream.GetBuffer(), 0, (int)memoryStream.Length);
                    }

I need to decrypt this encrypted string in UWP app. I searched in google. but unable to find any useful.

How to achieve this?

Universal Windows Platform (UWP)
{count} votes

1 answer

Sort by: Most helpful
  1. Junjie Zhu - MSFT 15,211 Reputation points Microsoft Vendor
    2023-03-15T06:31:14.5466667+00:00

    Hello @Petchiammal Rajumayandi ,

    Welcome to Microsoft Q&A!

    RijndaelManaged Class Method supports .NET Standard 2.0, 2.1, you can use it to encrypted string in UWP app.

    You can follow the code sample in the official document.

    1. Create an RijndaelManaged object with the specified key and IV.
    2. Create a decryptor to perform the stream transform.
    3. Create the streams used for decryption.
    4. Read the decrypted bytes from the decrypting stream and place them in a string.

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our [documentation] to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments