I'm pretty sure that you're dealing with the new RedSys SHA256 signature implementation. Also I saw that you have some issue with the 3DES encryption between PHP and C#.
First at all you must get the base 64 string with all the payment parameters. You can achieve it with this code:
public static string GetParameters(string merchantCode, string terminal, int currency, string transactionType, decimal amount, string merchantOrder, string merchantIdentifier, string merchantPost, string urlOk, string urlKo)
{
var jsonValues = new Dictionary<string, string>
{
{ "Ds_Merchant_Amount", amount.ToString().Replace(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator, "") },
{ "Ds_Merchant_Order", merchantOrder},
{ "Ds_Merchant_MerchantCode", merchantCode },
{ "Ds_Merchant_Currency", currency.ToString() },
{ "Ds_Merchant_TransactionType", transactionType },
{ "Ds_Merchant_Terminal", terminal },
{ "Ds_Merchant_Identifier", merchantIdentifier },
{ "Ds_Merchant_MerchantURL", merchantPost },
{ "Ds_Merchant_UrlOK", urlOk},
{ "Ds_Merchant_UrlKO", urlKo}
}.Select(kvp => "\"{0}\":\"{1}\"".Formato(kvp.Key.ToUpper(), kvp.Value));
var jsonString = "{" + string.Join(",", jsonValues) + "}";
return Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(jsonString));
}
Once you have the JSON string in base 64, you must apply 3DES to merchant order parameter with the key provided by RedSys:
public static string GetTransactionEncryptionKey(string merchantOrder, string encryptKey)
{
using (var tdes = new TripleDESCryptoServiceProvider())
{
tdes.IV = new byte[8] { 0, 0, 0, 0, 0, 0, 0, 0 };
tdes.Key = Convert.FromBase64String(encryptKey);
tdes.Padding = PaddingMode.Zeros;
tdes.Mode = CipherMode.CBC;
var toEncrypt = ASCIIEncoding.ASCII.GetBytes(merchantOrder);
var result = tdes.CreateEncryptor().TransformFinalBlock(toEncrypt, 0, toEncrypt.Length);
return Convert.ToBase64String(result);
}
}
As you can see, the encryption key provided by RedSys is base 64 string so you don't need to calculate the MD5 hash for the 3DES algorithm.
Then we go for the SHA256 signature:
public static string GetSignature(string base64Parameters, string base64tranEncryptKey)
{
using (var sha = new HMACSHA256(Convert.FromBase64String(base64tranEncryptKey)))
{
var hash = sha.ComputeHash(ASCIIEncoding.ASCII.GetBytes(base64Parameters));
return Convert.ToBase64String(hash);
}
}
Good luck!