python - 在 C 中验证 SHA256(python 生成)
问题描述
我正在尝试使用openssl/sha.h在C代码中使用passlib( https://passlib.readthedocs.io/en/stable/lib/passlib.hash.sha256_crypt.html )验证python生成的哈希。
对于密码“senhateste”,python passlib 生成了以下哈希:
$5$rounds=535000$e.cy1Y7iWc0OQjNC$7QbwABQMlBdHHd.UURPF.eoc0VTGOtM7yxxrOIe4OxC
其中有多个轮次、一个盐和一个校验和(以 $ 分隔)。
我试图在 C 中为原始密码生成一个哈希值,以与 Python 代码生成的密码进行比较,但我只得到一个字节数组(就像在线 sha256 哈希工具的那些)。
我正在考虑对 Pyhton 提供的相同轮数的密码进行循环哈希处理。但我不知道应该在哪里使用盐。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/sha.h>
int main (void) {
int i;
unsigned char s[] = "senhateste";
unsigned char *d = (unsigned char *) malloc(SHA256_DIGEST_LENGTH);
SHA256(s,strlen((char*)s), d);
for(i=0;i<SHA256_DIGEST_LENGTH;i++)
{
printf("%02x",d[i]);
}
printf("\n");
free(d);
return 0;
}
有什么建议吗?
解决方案
推荐阅读
- php - 刚设置时用户定义的变量为空
- bash - 在 bash 中排序和替换字符
- c# - 在 OpenShift 上使用 C# 进行签名验证时出错
- go-templates - 如何压缩两个数组
- c# - 方法调用后全局声明的变量返回 Null
- python - 使用 python 抓取网页时出错
- javascript - 如何在 React js 中访问登录的谷歌用户?
- reactjs - 如何修复 reactjs 语法错误:意外令牌?
- python - 如何使用 fit_generator 解决数据不平衡的问题
- ruby-on-rails - Rails rake 任务在不使用密件抄送的情况下循环多个电子邮件收件人