Created
January 12, 2022 09:21
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