Created
January 12, 2022 09:21
-
-
Save velotiotech/cdb5586a40feb3d05ac9491c2d27de77 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void get_random_string(char *random_str,int length) | |
{ | |
FILE *fp = fopen("/dev/urandom","r"); | |
if(!fp){ | |
perror("Unble to open urandom device"); | |
exit(EXIT_FAILURE); | |
} | |
fread(random_str,length,1,fp); | |
fclose(fp); | |
} | |
char random_string[11]; | |
//get random string | |
get_random_string(random_string,10); | |
//convert random string to base64 coz input string is coming from /dev/urandom and may contain binary chars | |
const int encoded_length = Base64encode_len(10); | |
base64_string=(char *)malloc(encoded_length+1); | |
Base64encode(base64_string,random_string,10); | |
base64_string[encoded_length]='\0'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment