vendredi 6 mars 2020

How to read /dev/urandom to an array

I have a C program that read random number from /dev/urandom to a array as a 256 bits key, but it seems not thing read. What happen to my program?

#include <stdlib.h>

#define LEN 32 // 256 bits
void main()
{

    unsigned char *key = (unsigned char *) malloc(sizeof(unsigned char)*LEN);
    FILE* random = fopen("/dev/urandom", "r");
    fread(key, sizeof(unsigned char)*LEN, 1, random);
    fclose(random);
}



Aucun commentaire:

Enregistrer un commentaire