0

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.

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;
    }
}
HaemEternal
  • 2,229
  • 6
  • 31
  • 50
Sajid Ali
  • 1
  • 2
  • 3
  • WinRT has completely different crypto APIs. http://pclcontrib.codeplex.com/ might have a wrapper. – CodesInChaos Nov 25 '14 at 15:37
  • Your code has major cryptographic issues. 1) The key seems to be a string not a proper key. Either generate a proper key (and base64 encode it if you need a string) or use a KDF. 2) The IV is fixed. The whole point of an IV is that it's different for each encryption. 3) Lack MAC enables active attacks, including padding oracles. – CodesInChaos Nov 25 '14 at 15:39

0 Answers0