using namespace std;
char
*
base64Encode(const char
*
buffer
,
int
length,
bool
newLine);
extern
"C"
__declspec(dllexport) void test()
{
bool
newLine
=
false;
string
input
=
"Hello World!"
;
char
*
encode
=
base64Encode(
input
.c_str(),
input
.length(), newLine);
cout <<
"Base64 Encoded : "
<< encode << endl;
cin.get();
}
char
*
base64Encode(const char
*
buffer
,
int
length,
bool
newLine)
{
BIO
*
bmem
=
NULL;
BIO
*
b64
=
NULL;
BUF_MEM
*
bptr;
b64
=
BIO_new(BIO_f_base64());
if
(!newLine) {
BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
}
bmem
=
BIO_new(BIO_s_mem());
b64
=
BIO_push(b64, bmem);
BIO_write(b64,
buffer
, length);
BIO_flush(b64);
BIO_get_mem_ptr(b64, &bptr);
BIO_set_close(b64, BIO_NOCLOSE);
char
*
buff
=
(char
*
)malloc(bptr
-
>length
+
1
);
memcpy(buff, bptr
-
>data, bptr
-
>length);
buff[bptr
-
>length]
=
0
;
BIO_free_all(b64);
return
buff;
}