added local base64_encode fn
This commit is contained in:
parent
5cc8c43b62
commit
0b3cb2f957
@ -34,24 +34,34 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
EVP_PKEY *keypair = NULL; //KEYPAIR
|
EVP_PKEY *keypair = NULL; //KEYPAIR
|
||||||
|
|
||||||
void read_file(FILE *file, char **output)
|
//LOCAL
|
||||||
|
char *base64_encode(char *data)
|
||||||
{
|
{
|
||||||
//VARIABLES
|
//VARIABLES
|
||||||
int buffer_size;
|
BIO *bio;
|
||||||
char *buffer;
|
BIO *b64;
|
||||||
|
BUF_MEM *buffer_ptr;
|
||||||
|
|
||||||
//GET LENGTH
|
//CREATE BIO
|
||||||
fseek(file, 0, SEEK_END);
|
b64 = BIO_new(BIO_f_base64());
|
||||||
buffer_size = ftell(file);
|
bio = BIO_new(BIO_s_mem());
|
||||||
rewind(file);
|
bio = BIO_push(b64, bio);
|
||||||
|
|
||||||
//READ
|
BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL); //NO NEWLINES
|
||||||
buffer = why2_calloc(buffer_size + 1, sizeof(char));
|
BIO_write(bio, data, strlen(data)); //ENCODE
|
||||||
if (fread(buffer, buffer_size, 1, file) != 1) why2_die("Reading keyfile failed!");
|
BIO_flush(bio);
|
||||||
buffer[buffer_size] = '\0';
|
|
||||||
|
|
||||||
//ASSIGN OUTPUT
|
BIO_get_mem_ptr(bio, &buffer_ptr); //GET PTR
|
||||||
*output = buffer;
|
char *b64text = why2_malloc(buffer_ptr -> length + 1); //ALLOCATE
|
||||||
|
|
||||||
|
//COPY
|
||||||
|
memcpy(b64text, buffer_ptr -> data, buffer_ptr -> length);
|
||||||
|
b64text[buffer_ptr -> length] = '\0'; //NULL-TERM
|
||||||
|
|
||||||
|
//DEALLOCATION
|
||||||
|
BIO_free_all(bio);
|
||||||
|
|
||||||
|
return b64text;
|
||||||
}
|
}
|
||||||
|
|
||||||
//GLOBAL
|
//GLOBAL
|
||||||
|
Loading…
x
Reference in New Issue
Block a user