Note that there are some explanatory texts on larger screens.

plurals
  1. POBase64 encoding and decoding with OpenSSL
    primarykey
    data
    text
    <p>I've been trying to figure out the openssl documentation for base64 decoding and encoding. I found some code snippets below</p> <pre class="lang-cxx prettyprint-override"><code>#include &lt;openssl/sha.h&gt; #include &lt;openssl/hmac.h&gt; #include &lt;openssl/evp.h&gt; #include &lt;openssl/bio.h&gt; #include &lt;openssl/buffer.h&gt; char *base64(const unsigned char *input, int length) { BIO *bmem, *b64; BUF_MEM *bptr; b64 = BIO_new(BIO_f_base64()); bmem = BIO_new(BIO_s_mem()); b64 = BIO_push(b64, bmem); BIO_write(b64, input, length); BIO_flush(b64); BIO_get_mem_ptr(b64, &amp;bptr); char *buff = (char *)malloc(bptr-&gt;length); memcpy(buff, bptr-&gt;data, bptr-&gt;length-1); buff[bptr-&gt;length-1] = 0; BIO_free_all(b64); return buff; } char *decode64(unsigned char *input, int length) { BIO *b64, *bmem; char *buffer = (char *)malloc(length); memset(buffer, 0, length); b64 = BIO_new(BIO_f_base64()); bmem = BIO_new_mem_buf(input, length); bmem = BIO_push(b64, bmem); BIO_read(bmem, buffer, length); BIO_free_all(bmem); return buffer; } </code></pre> <p>This only seems to work for single line strings such as "Start", the moment I introduce complex strings with newlines and spaces etc it fails horribly.</p> <p>It doesn't even have to be openssl, a simple class or set of functions that do the same thing would be fine, theres a very complicated build process for the solution and I am trying to avoid having to go in there and make multiple changes. The only reason I went for openssl is because the solution is already compiled with the libraries.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload