php - 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>
解决方案
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);
推荐阅读
- javascript - 期望字符串(用于内置组件)或类/函数(用于复合组件)但未定义
- python - 为什么在使用 pandas 读取 csv 时会自动删除前面的引号?
- c# - 我可以异步运行同步代码以获得性能吗?
- php - 将响应 curl 函数从字符串转换为对象或数组 PHP
- ios - 麦克风和扬声器播放时按钮无响应
- python - Python 和 Matlab 的结果略有不同
- django - Django 序列化器字符串浮动
- ui-automation - UIATable 操作 GetCellValue 引发错误“由于从 UI 自动化继承的 API 调用缺失或损坏而失败”
- python - 在python中重命名多个文件并在前面计数
- javascript - 如何更改amcharts中放大/缩小和主页按钮的形状?我在 amcharts 库中没有找到任何解决方案。请让我进入解决方案