python-3.x - 如何在 Python 中计算列表的 SHA-256 哈希?
问题描述
我正在尝试复制 JS 方法:
JS代码:
const toHexCopy = (buffer) => {
return [...new Uint8Array (buffer)]
.map (b => b.toString (16).padStart (2, "0"))
.join ("");
};
ar = new Uint8Array([0, 1, 2]);
hash = await crypto.subtle.digest('SHA-256', ar)
console.log(toHexCopy(hash))
// returns 039058c6f2c0cb492c533b0a4d14ef77cc0f78abccced5287d84a1a2011cfb81
如何在 Python 中复制它?
解决方案
from hashlib import sha256
print(sha256(bytes([1, 2, 3])).hexdigest())
推荐阅读
- android - OpenGL ES 2 投影切换前景和背景
- php - 当 PHP 请求 API 失败时如何处理错误
- c - 选择数组中的某些元素以创建新数组
- angular - 角度监听网络调用的开始和完成(下载功能)以显示进度条或微调器
- prolog - 为 n 位创建所有组合时出现意外的重复结果
- python-3.x - 如何在不让我的电脑死机的情况下加载一堆图像进行深度学习
- symfony - Symfony 非规范化:递归非规范化不起作用
- ruby-on-rails - Ruby哪里数组不为空?
- python - 在python进程的后台线程中从队列中提取数据
- python - 更改选定的背景 ttk 树视图