我正在創建一個C程序來生成密碼。有沒有辦法使用sodium.h生成〜(126)的字符空間(32)?或者其他方式來生成安全的字符串?
rand()
用C不斷產生一些相同的一組甚至使用here,但更好的發現srand((unsigned int)**main + (unsigned int)&argc + (unsigned int)time(NULL))
字符串比使用srand(time(NULL))
我發現這個answer,我終於知道如何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();
}