question

AndrewKayaga-2560 avatar image
0 Votes"
AndrewKayaga-2560 asked ·

CryptoJS Encryption and Decryption in UWP C#

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;
         }
 
     }
uwp
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

0 Answers