Click here to Skip to main content
15,895,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

Passphrase: e615242cd9498f2a38995d516bb5f8c819be91a4

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


What I have tried:

Below is the code that requires an key and Iv and what to decrpyt but i dont know how to get the key.


C#
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;
        }

    }
Posted
Updated 18-Apr-20 0:38am
v3
Comments
Richard MacCutchan 18-Apr-20 4:47am    
The encryptor is converting the string to ASCII, but the decryptor is getting it as Unicode. There is no need for either of these conversions. Just encrypt the original string as is, and it should work.
Member 14805662 18-Apr-20 5:07am    
I have an Encrypted String that needs to be decrypted. So when you say i should encrypt the original string i dont understand you. Please add more light. Thank you
Richard MacCutchan 18-Apr-20 5:50am    
Look at your code. You convert a string to ASCII and then to binary, and encrypt the result. You do not need those conversions, just encrypt the actual original data.

1 solution

Have you looked at this link?

Google Groups - Crypto JS[^]

If that doesn't help, I googled "decrypt cryptojs with c#, and got these results:

DuckDuckGo — Privacy, simplified.[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900