简体   繁体   中英

asp.net equivalant of php's sha1

I need help some to make this one line of code to which works on php server to work on asp.net server, in other words asp.net equivalant of the following php code. Thanks.

Here date('Ymd H:i:s') results into a string like this one '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>

The output of this code on php at time 2018-06-13 10:44:40 is

    <iframe src="https://example.com/index.php?hash=dd6221b41119bf98aac6658fb4d99d41a7a93a15" ></iframe>
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;
    }

And use it like string sha1 = CalculateSha1(toGenerate, Encoding.Default);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM