- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何用 C 语言创建一个简单的密码哈希函数?我知道有一个可用的标准库,crypt.h
,还有openssl/sha.h
但这不会产生字符串。我尝试了不同的方法来打印 sha256 字符串,但该字符串与同一单词的其他 sha256 字符串不一样。
我在本网站的一个主题中找到了用于哈希到 sha256 的代码:
char input[] = "hello";
int length = sizeof(input);
SHA256_CTX context;
unsigned char md[SHA256_DIGEST_LENGTH];
SHA256_Init(&context);
SHA256_Update(&context, (unsigned char *)input, length);
SHA256_Final(md, &context);
printf("%02x\n", md); // every time different value: c94ce410, 46d384c0 ..
printf("sizeof md = %zu\n", sizeof(md));
int i;
for(i = 0; i <= sizeof(md); i++) {
printf("%02x", md[i]); // not a sha256..
printf("%u", md[i]); // only numeric, not correct..
}
printf("\n");
它生成的字符串是: f3aefe62965a91903610f0e23cc8a69d5b87cea6d28e75489b0d2ca02ed7993c62
但这不是 hello
的 sha256 字符串,因为它不被在线解密服务识别。我正在使用#include <openssl/sha.h>
对于这个。
编辑:
正确设置:
int length = strlen(input);
int i;
for(i = 0; i < sizeof(md); i++) {
printf("%0x", md[i]);
//printf("%u", md[i]);
}
printf("\n");
现在生成了正确的 sha256 哈希字符串。
最佳答案
你的长度错误。 typedef 返回类型的长度,这里的字符数组以\0 结尾。您需要使用 strlen 来代替。
关于c - C 中的密码散列为字符串散列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48600002/
我想我接近了但不确定: 我有一个包含电子邮件地址、个人和工作的示例表。我正在尝试创建一个包含单个地址的新表。 然后插入一个电子邮件地址,例如:如果用户有工作电子邮件但没有个人电子邮件,则插入工作电子邮
在列上允许 NULL 值通常是为了允许表示不存在的值。使用 NVARCHAR 时,可能会出现空字符串,而无需将列设置为 NULL。在大多数情况下,我看不到带有空字符串的 NVARCHAR 与此类列的
我有下表 security 证券: id | bbg_ticker | ticker | currency | exchange | type -------+------
我正在处理 DB2 上的一些 SQL 查询。是否可以选择表中的所有列并在该选择语句中使用“as”关键字指定某些条件?例如,这个查询是否可行: select *, col1 + col2 as
我有一个名为 TP_Roles 的表。 该表结构是: Id PK, int, not null Role_Name varchar(200), null IsActive bit, nul
我有一个这样的表: +----+-------+-------+-------+ | Id | Flag1 | Flag2 | Flag3 | +----+-------+-------+------
自从我尝试创建此 MySQL View 以来,我的头痛就开始了,其中一列的结果值为 NULL。我需要一个像 0 这样的真实值。 我从表 1 中取出我的 ID 并在表 2 中进行比较,因此不确定是否有一
我必须制作一个符合特定条件的数据结构。 首先这 4 个函数必须在 O(log(n)) 中: insert(Object o) insert(int index, Object o) delete(
据我了解, useRef 返回的容器总是相同的——但在 useEffect 和类似函数中引用它们会导致 eslint 详尽的警告。在这种情况下忽略警告是否安全,以及避免用警告阻塞输出日志和禁用行注释的
我有一个很好的算法,可以返回同一条船上连续安装的最旧的部分安装:How to get oldest part installation of consecutive installations the
我有一个存储过程,它有一个字符串参数。当我使用包含一些特殊字符(如“ş”或“ğ”)的单词进行调用时,它返回错误代码:1366。第 1 行的“personalNames”列的字符串值不正确:“\xC5\
文件: Person1:AP Person2:AP Person3:KE Person4:KE Person5:UK Person6:AP Person7:UK Person8:AP 我试过的是: i
我想知道如果 A 列为空,我如何显示 B 列中的数据。原因是如果我们从我们的一个制造商那里获得产品,它会被放在不同的列中。但是,当我去构建报告时,这两列本质上是相同的东西,而且它把图表扔掉了。任何帮助
因此,如果列为空或 null,我会尝试过滤掉一些行。 我该怎么做? 看来我需要某种类似于 SQL 的语句。 我想要这样的东西: t.DefaultView.RowFilter = string.For
我想强制所有 Oracle DATE 列为 LocalDateTime。 我尝试过的: LOCALDATETIME java.time.LocalDateTime DATE\
我正在尝试为我的数据库创建一个 View 。 CREATE VIEW `latest` AS SELECT r.id as recheck_id, f.id as failure_id, r.`whe
我这里有一些动态生成列表的代码: transaction.executeSql('SELECT * FROM table1 WHERE checkb = "true" ORDER BY date DE
如果我有下表: canAssign ------------ 1 有没有办法将列标题文本(例如,canAssign 等)添加到 CheckedListBox 作为用户可以检查的
这个问题可能很愚蠢,但这是我第一次接触 gcc 文档。 我知道basic_streambuf::pubseekoff() 是模板类basic_streambuf 的公共(public)成员函数,但它没
我需要用户能够以以下格式将数据输入到文本区域。 姓名,电子邮件@email.com 姓名,电子邮件@email.com 姓名,电子邮件@email.com 然后信息将被发送到 mysql 数据库。我的
我是一名优秀的程序员,十分优秀!