Skip to content

Can not get the decrypted payload as provided example #20

Description

@TolaGitHub
  1. Is the param named "payload" value valid for the $client_secret = "0123abcd4567efgh1234567890"?
    (https://www.example.com/my-app-iframe-page?payload=353035362c226163636573735f746f6b656e223a22776d6&app_state=orderId%3A%2012&cache-killer=13532)

  2. Is the below decryption function code inside C# valid? Please advice, I have stucked with for so long, thanks.

        public static CheckoutInfo GetPayload(string cipherText, string clientKey)
        {
            try
            {
                // MARK: - Ecwid Decryption Rules
                cipherText = cipherText.Replace("-", "+").Replace("_", "/");
                cipherText = cipherText.PadRight(cipherText.Length + (4 - (cipherText.Length % 4)), '=');
                clientKey = clientKey.Substring(0, 16);

                var jsonData = AES128Decrypt(cipherText, clientKey);
                return JsonConvert.DeserializeObject<CheckoutInfo>(jsonData);
            }
            catch (Exception e)
            {
                Debug.Write("error=> " + e.StackTrace);
                return null;
            }
        }

        public static string AES128Decrypt(string cipherText, string clientKey)
        {
            AesManaged aesObj = new AesManaged();
            aesObj.Mode = CipherMode.CBC;
            aesObj.Padding = PaddingMode.Zeros;
            aesObj.KeySize = 128;
            aesObj.BlockSize = 128;

            var decoded = Convert.FromBase64String(cipherText);
            var key = Encoding.UTF8.GetBytes(clientKey);

            var iv = new byte[16];
            Array.Copy(decoded, 0, iv, 0, iv.Length);

            //var payload = new byte[decoded.Length - iv.Length];
            //Array.Copy(decoded, iv.Length, payload, 0, payload.Length);

            var payloadLen = decoded.Length - iv.Length;
            if (payloadLen < 16)
                payloadLen = 16;
            else if (payloadLen > 16 && payloadLen < 32)
                payloadLen = 32;
            else if (payloadLen > 32)
                payloadLen = 64;

            var payload = new byte[payloadLen];
            Array.Copy(decoded, iv.Length, payload, 0, decoded.Length - iv.Length);

            aesObj.Key = key;
            aesObj.IV = iv;

            var textByte = aesObj.CreateDecryptor().TransformFinalBlock(payload, 0, payload.Length);
            var result = Encoding.UTF8.GetString(textByte);
            return result;
        }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions