locked
CryptoJS Encryption and Decryption in UWP C# RRS feed

  • Question

  • I have a video URL link which is encrypted using CryptoJS on a server and my job in my Universal Windows App in c# is to decrypt the sent content and get the original video URL link.

    I have tried to use AES Decryption but still getting errors. Below is the array that is generated when the URL is encrypted on the server

    Passphrase: e615242cd9498f2a38995d516bb5f8c819be91a4

    Encrypted String: {"ct":"yA8RGCPPvX4f9QhIJ0ga2oOutxnUEcddh5iBQalPoAlNZgutVTefOdvwO54D7Bwl2eTr+i/u9/cDL6sVcvZ9+hXfr1eZ/sYjjKX0qSr+yPjA+CrQWeApBPVtS45JPCY8ekB2pZah8uqqtPpfeV5T8xHzrkJJbS0d+VqFhj1aqao/qWKdCaD6BK75QfnkBz0XzQd/ulK7saoLGO2t7LHhlg==","iv":"0fa9a8205ccb9894e416e8ba85bc4960","s":"60f24ca1a8380cac"}

    Below is the code that requires an key and Iv and what to decrpyt

        class AesEnDecryption
        {
            // Key with 256 and IV with 16 length
            private string AES_Key = "";
            private string AES_IV = "";
            private IBuffer m_iv = null;
            private CryptographicKey m_key;
    
            public AesEnDecryption()
            {
    
    
                IBuffer key = Convert.FromBase64String(AES_Key).AsBuffer();
                m_iv = Convert.FromBase64String(AES_IV).AsBuffer();
                SymmetricKeyAlgorithmProvider provider = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesCbcPkcs7);
                m_key = provider.CreateSymmetricKey(key);
            }
    
            public byte[] Encrypt(byte[] input)
            {
    
                IBuffer bufferMsg = CryptographicBuffer.ConvertStringToBinary(Encoding.ASCII.GetString(input), BinaryStringEncoding.Utf8);
                IBuffer bufferEncrypt = CryptographicEngine.Encrypt(m_key, bufferMsg, m_iv);
                return bufferEncrypt.ToArray();
            }
    
            public string Decrypt(byte[] input)
            {
                IBuffer bufferDecrypt = CryptographicEngine.Decrypt(m_key, input.AsBuffer(), m_iv);
               
                string one = Encoding.Unicode.GetString(bufferDecrypt.ToArray());
                return one;
            }
    
        }


    Saturday, April 18, 2020 7:15 AM

All replies

  • Hello,

    Please ask your question here https://docs.microsoft.com/answers/index.html


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Saturday, April 18, 2020 10:33 AM