locked
Decryption problem in Windows RT project.

    Question

  • this code is working well in Windows Phone Silverlight project.

    but this not working in Windows RT project.

    its syay cryptographic and Aes and AesManaged classes missing etc.

    please help me thanks.

    i dont really need password and salt. its just simple take string and decrypt it.

    how i can use this in Windows RT projects or in PCL project.

    public class DecryptionHelper
        {
            public static string Decrypt(string base64StringToDecrypt)
            {
                if (string.IsNullOrEmpty(base64StringToDecrypt))
                    return string.Empty;
                //Set up the encryption objects
                using (Aes acsp = GetProvider(Encoding.UTF8.GetBytes(Constants.EncryptionKey)))
                {
                    byte[] RawBytes = Convert.FromBase64String(base64StringToDecrypt);
                    ICryptoTransform ictD = acsp.CreateDecryptor();
                    //RawBytes now contains original byte array, still in Encrypted state
                    //Decrypt into stream
                    MemoryStream msD = new MemoryStream(RawBytes, 0, RawBytes.Length);
                    CryptoStream csD = new CryptoStream(msD, ictD, CryptoStreamMode.Read);
                    //csD now contains original byte array, fully decrypted
                    //return the content of msD as a regular string
                    return (new StreamReader(csD)).ReadToEnd();
                }
            }

            private static Aes GetProvider(byte[] key)
            {
                Aes result = new AesManaged();
                result.GenerateIV();
                result.IV = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
                byte[] RealKey = GetKey(key, result);
                result.Key = RealKey;
                return result;
            }

            private static byte[] GetKey(byte[] suggestedKey, SymmetricAlgorithm p)
            {
                byte[] kRaw = suggestedKey;
                List<byte> kList = new List<byte>();
                for (int i = 0; i < p.LegalKeySizes[0].MinSize; i += 8)
                {
                    kList.Add(kRaw[(i / 8) % kRaw.Length]);
                }
                byte[] k = kList.ToArray();
                return k;
            }
        }

    Tuesday, November 25, 2014 2:37 PM

All replies

  • Which part isn't working?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, November 25, 2014 9:17 PM
    Moderator
  • Decrypt method

    following are not working in WindowsRT 8.1 project

    their namespace not available.

    1. Aes.

    2. ICryptoTransform ictD = acsp.CreateDecryptor();

    3. MemoryStream msD = new MemoryStream(RawBytes, 0, RawBytes.Length);

    4.  CryptoStream csD = new CryptoStream(msD, ictD, CryptoStreamMode.Read);

    i have pasted whole class u can drop  in project use decrypt method pass encrypted value to it. then u will see what is wrong with it.

    Wednesday, November 26, 2014 4:39 PM
  • Does this help?

    https://canbilgin.wordpress.com/2012/10/03/simple-aes-symmetric-key-encryption-in-winrt/


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, November 26, 2014 4:51 PM
    Moderator
  • Hi,

    Thanks your help.

    one problem am facing again.

    Data cyclic redundancy error on decryption method.

    Monday, December 1, 2014 4:30 PM