sha-256算法python
时间: 2023-08-16 20:10:38 浏览: 146
SHA-256.zip_sha-256_sha256写法
SHA-256算法是一种密码哈希函数,用于将输入数据转换为固定长度的哈希值。在Python中,可以使用hashlib库来实现SHA-256算法。以下是一个示例代码:
```python
import hashlib
def sha256(data):
hash_object = hashlib.sha256(data.encode())
hex_dig = hash_object.hexdigest()
return hex_dig
data = "Rosetta code"
sha256_hash = sha256(data)
print(sha256_hash)
```
运行以上代码,将输出SHA-256算法对输入数据"Rosetta code"的哈希值。
#### 引用[.reference_title]
- *1* [python实现SHA256](https://blog.csdn.net/leshen_88/article/details/118852245)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [Python实现SHA-1算法,附带完整源代码](https://blog.csdn.net/code_welike/article/details/130896161)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [SHA-256算法【代码实现】](https://blog.csdn.net/qq_36721220/article/details/100730342)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文