Beispiel #1
0
static void do_cipher(char* pw, int operation)
{
   long ebuflen;
   unsigned char  buf[U_BUFLEN];
   unsigned char ebuf[U_BUFLEN + 8];

   U_INTERNAL_TRACE("do_cipher(%s,%p)", pw, operation)

#  ifdef __MINGW32__
   (void) setmode(1, O_BINARY);
#  endif

   while (true)
      {
      int readlen = read(STDIN_FILENO, buf, sizeof(buf));

      if (readlen <= 0)
         {
         if (readlen == 0) break;
         else
            {
            perror("read");

            exit(1);
            }
         }

      if (operation == U_ENCRYPT) ebuflen = u_base64_encode(                      buf, readlen, ebuf);
      else                        ebuflen = u_base64_decode((const char* restrict)buf, readlen, ebuf);

      write(STDOUT_FILENO, ebuf, ebuflen);
      }
}
Beispiel #2
0
void UBase64::encode(const char* s, uint32_t n, UString& buffer)
{
   U_TRACE(0, "UBase64::encode(%.*S,%u,%.*S)", n, s, n, U_STRING_TO_TRACE(buffer))

#ifdef DEBUG
   uint32_t length = ((n + 2) / 3) * 4, num_lines = (u_base64_max_columns ? length / u_base64_max_columns + 1 : 0);

   U_INTERNAL_DUMP("buffer.capacity() = %u length = %u num_lines = %u", buffer.capacity(), length, num_lines)

   U_ASSERT(buffer.capacity() >= length + num_lines + 1)
#endif

   uint32_t pos = u_base64_encode((const unsigned char*)s, n, (unsigned char*)buffer.data());

   buffer.size_adjust(pos);
}
Beispiel #3
0
int main(int argc, char* argv[])
{
   unsigned char l[6];
   unsigned char im[70*200];
   unsigned char gif[GIF_SIZE];
   unsigned char encoded[GIF_SIZE * 3];

   captcha(im, l);
   makegif(im, gif);

   U_ClientImage_request_nocache = true;

   set_reply_capacity(1024 + GIF_SIZE * 3);

   (void) u__snprintf(get_reply(), get_reply_capacity(), "<img src=\"data:img/gif;base64,%.*s\">", u_base64_encode(gif, GIF_SIZE, encoded), encoded);

   return 200;
}