我正在创建一个 C 程序来生成密码。
rand()
srand((unsigned int)**main + (unsigned int)&argc + (unsigned int)time(NULL))
在 C 中,即使使用在此处找到的,也会继续生成一些相同的字符串集,但比使用更好srand(time(NULL))
我找到了这个答案,我终于知道如何将 libsodium 链接到我的项目。
之后,我意识到我只能为 设置上限randombytes_uniform()
,下限始终为0
。
并使用randombytes_random()
给我所有不能在密码中使用的字符。
谁能知道如何使用钠或任何安全的方式生成字符空间(32)到字符〜(126)?
这是原始代码:
#include <stdio.h>
#include <stdlib.h>
#include "sodium.h"
#pragma warning (disable:4996)
void main(int argc, char **argv){
/* Length of the password */
int length, num, temp, number;
num = 10;
length = 10;
number = num;
clear_screen();
/* Seed number for rand() */
srand((unsigned int)**generate_standard_password + (unsigned int)&argc + (unsigned int)time(0));
while (num--)
{
temp = length;
printf("\n\t%2d. ", (number - num));
while (temp--) {
putchar(rand() % 56 + 65);
srand(rand());
}
temp = length;
}
printf("\n\n\t");
system_pause();
}