Decryption in Windows RT project

101 views Asked by At

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;
    }
}
0

There are 0 answers