首页 > 解决方案 > php sha1的asp.net等价物

问题描述

我需要一些帮助才能使在 php 服务器上运行的这一行代码在 asp.net 服务器上运行,换句话说,asp.net 等效于以下 php 代码。谢谢。

这里 date('Ymd H:i:s') 结果变成了这样的字符串 '2018-06-13 10:44:40'。

<iframe src="<?php echo 'https://example.com/index.php?hash='.sha1(date('Y-m-d H:i:s')); ?>" ></iframe>

这段代码在 2018-06-13 10:44:40 时间在 php 上的输出是

    <iframe src="https://example.com/index.php?hash=dd6221b41119bf98aac6658fb4d99d41a7a93a15" ></iframe>

标签: phpasp.net

解决方案


using System.Security.Cryptography;//import


//our method to calculate
private static string CalculateSha1(string text, Encoding enc)
    {
        byte[] buffer = enc.GetBytes(text);
        SHA1CryptoServiceProvider cryptoTransformSha1 =
        new SHA1CryptoServiceProvider();
        string hash = BitConverter.ToString(
            cryptoTransformSha1.ComputeHash(buffer)).Replace("-", "");

        return hash;
    }

并像使用它一样string sha1 = CalculateSha1(toGenerate, Encoding.Default);


推荐阅读