小编Jul*_*ral的帖子

从 C# 到 PHP 的函数

我需要将这些用 C# 开发的加密系统转换为 PHP。这些是输入数据。客户 ID、转换为字符串的 JSON 对象和私钥。

codigoCliente: 1002

数据:{"codigoCliente":1002,"codigoArticulo":"30-07483","cantidad":1}

claveSecretaServicio:RFlTfDIwMjBXZWJQYWdlX0V4dGVybmF

我需要得到这个哈希结果:WGHGEY830J3WeadO1o4NGNLYZ9lY7xvquol5igE+hLU=

这是 C# 中的调用:GetHash(modelo.CodigoCliente.ToString(), JsonSerializer.Serialize(modelo), “WGHGEY830J3WeadO1o4NGNLYZ9lY7xvquol5igE+hLU=”);

转换为 PHP 的 C# 函数是这些。

public static string GetHash(string codigoCliente, string datos, string claveSecretaServicio)
{
    var claveSecretaBytes = System.Convert.FromBase64String(claveSecretaServicio);
    var claveOperacion = Encrypt3DES(codigoCliente, claveSecretaBytes);
    var firmaBytes = GetHMACSHA256(datos, claveOperacion);
    return System.Convert.ToBase64String(firmaBytes);
}

private static byte[] Encrypt3DES(string codigoCliente, byte[] key)
{
    var codigoClienteBytes = System.Text.Encoding.UTF8.GetBytes(codigoCliente);
    TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
    byte[] SALT = new byte[8] { 0, 0, 0, …
Run Code Online (Sandbox Code Playgroud)

php c# encryption

-3
推荐指数
1
解决办法
214
查看次数

标签 统计

c# ×1

encryption ×1

php ×1