小编Rob*_*tea的帖子

C#中strtr php函数的转换

需要将此 php 代码转换为 C#

strtr($input, '+/', '-_')
Run Code Online (Sandbox Code Playgroud)

是否存在等效的 C# 函数?

php c# asp.net replace strtr

5
推荐指数
1
解决办法
1658
查看次数

PHP和C#HMAC SHA256

我需要在C#中转换以下php代码:

$res = mac256($ent, $key);
$result = encodeBase64($res);
Run Code Online (Sandbox Code Playgroud)

哪里

function encodeBase64($data)
{
    $data = base64_encode($data);
    return $data;
}
Run Code Online (Sandbox Code Playgroud)

function mac256($ent,$key)
{
    $res = hash_hmac('sha256', $ent, $key, true);//(PHP 5 >= 5.1.2)
    return $res;
}
Run Code Online (Sandbox Code Playgroud)

我使用以下C#代码:

byte[] res = HashHMAC(ent, key);
string result = System.Convert.ToBase64String(res);
Run Code Online (Sandbox Code Playgroud)

哪里

public byte[] HashHMAC(string ent, byte[] key)
{
   byte[] toEncryptArray =System.Text.Encoding.GetEncoding(28591).GetBytes(ent);

   HMACSHA256 hash = new HMACSHA256(key);
   return hash.ComputeHash(toEncryptArray);
}
Run Code Online (Sandbox Code Playgroud)

这个链接提供完整的php源代码

我也在php中检查了这篇文章hmac_sha256和c#的区别

而这一个C#相当于PHP中的hash_hmac

但结果却不尽相同.

php c# sha256 hmac

2
推荐指数
1
解决办法
6126
查看次数

标签 统计

c# ×2

php ×2

asp.net ×1

hmac ×1

replace ×1

sha256 ×1

strtr ×1