[UWP]AES Encryption RRS feed

  • Question

  • I'm trying to encrypt Strings with AES and I found a way to do it under Windows 8.1 with System.Security.Cryptography.AES...

    But that's not existing under Windows 10 and there is nothing under Windows.Security.Cryptography...

    Thursday, October 22, 2015 7:48 PM


All replies

  • Hi soeren_G,

    >>But that's not existing under Windows 10 and there is nothing under Windows.Security.Cryptography...

    System.Security.Cryptography namespace is available in traditional desktop application, but not for UWP apps.

    In UWP apps, to implement AES Encryption, we need to use the following namespaces:

    Windows.Security.Cryptography namespace & Windows.Security.Cryptography.Core namespace

    See also this similar thread: https://social.msdn.microsoft.com/Forums/en-US/52080335-0016-4370-889b-3afe0c0dcb7a/how-to-do-simple-aes-encryptiondecryption-in-metro?forum=winappswithcsharp

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, October 23, 2015 9:25 AM
  • I am not very well versed in encryption code and have never written a UWP app before. I have this function from a desktop app I wrote, is there anyone who can please help me convert this to UWP with the correct namespaces?

    Imports System.Security.Cryptography
    Imports System.IO
    Imports System.Text

    Public Function EncryptString_Aes(ByVal plainText As String) As String
            Dim sb As StringBuilder = New StringBuilder()
            ' Create an AesCryptoServiceProvider object
            ' with the specified key and IV.
            Using aesAlg As New AesCryptoServiceProvider()
                aesAlg.Key = aesKey
                ' Create a decrytor to perform the stream transform.
                Dim encryptor As ICryptoTransform = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV)
                ' Create the streams used for encryption.
                Dim msEncrypt As New MemoryStream()
                Using csEncrypt As New CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write)
                    Using swEncrypt As New StreamWriter(csEncrypt)
                        'Write all data to the stream.
                    End Using
                End Using
            End Using
            Return sb.ToString.Replace("-", "")
        End Function

    aesKey is a public variable of byte(32) that has the current key in memory

    Gary Ritter - Nokia Lumia

    Monday, October 17, 2016 12:08 AM