1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * The contents of this file are subject to the Mozilla Public License
9 * Version 1.0 (the "License"); you may not use this file except in
10 * compliance with the License. You may obtain a copy of the License at
11 * http://www.mozilla.org/MPL/
13 * Software distributed under the License is distributed on an "AS IS"
14 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
15 * License for the specific language governing rights and limitations
18 * The Original Code is Curl.
20 * The Initial Developer of the Original Code is Daniel Stenberg.
22 * Portions created by the Initial Developer are Copyright (C) 1998.
23 * All Rights Reserved.
25 * ------------------------------------------------------------
27 * - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
31 * $Source: /cvsroot/curl/curl/lib/base64.c,v $
33 * $Date: 1999-12-29 14:21:17 $
38 * ------------------------------------------------------------
39 ****************************************************************************/
43 /* ---- Base64 Encoding --- */
44 static char table64
[]=
45 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
47 void base64Encode(char *intext
, char *output
)
49 unsigned char ibuf
[3];
50 unsigned char obuf
[4];
55 for (i
= inputparts
= 0; i
< 3; i
++) {
65 obuf
[0] = (ibuf
[0] & 0xFC) >> 2;
66 obuf
[1] = ((ibuf
[0] & 0x03) << 4) | ((ibuf
[1] & 0xF0) >> 4);
67 obuf
[2] = ((ibuf
[1] & 0x0F) << 2) | ((ibuf
[2] & 0xC0) >> 6);
68 obuf
[3] = ibuf
[2] & 0x3F;
71 case 1: /* only one byte read */
72 sprintf(output
, "%c%c==",
76 case 2: /* two bytes read */
77 sprintf(output
, "%c%c%c=",
83 sprintf(output
, "%c%c%c%c",
94 /* ---- End of Base64 Encoding ---- */