Answered by:
[UWP]AES Encryption

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...
- Edited by Franklin ChenMicrosoft employee Friday, October 23, 2015 9:22 AM Subject
Thursday, October 22, 2015 7:48 PM
Answers
-
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.- Proposed as answer by Franklin ChenMicrosoft employee Wednesday, November 4, 2015 1:58 AM
- Marked as answer by Barry Wang Thursday, November 5, 2015 1:32 AM
Friday, October 23, 2015 9:25 AM
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.- Proposed as answer by Franklin ChenMicrosoft employee Wednesday, November 4, 2015 1:58 AM
- Marked as answer by Barry Wang Thursday, November 5, 2015 1:32 AM
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 aesAlg.GenerateIV() ' 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. swEncrypt.Write(plainText) End Using sb.Append(BitConverter.ToString(aesAlg.IV)) sb.Append(BitConverter.ToString(msEncrypt.ToArray)) 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