SequoiaDB
 All Classes Namespaces Files Functions Macros Pages
Macros | Functions
base64c.h File Reference

Encode binary data using printable characters. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Macros

#define SDB_INLINE   static
 
#define SDB_EXPORT   __declspec(dllimport)
 
#define SDB_EXTERN_C_START
 
#define SDB_EXTERN_C_END
 

Functions

SDB_EXPORT int base64Encode (const char *s, int in_size, char *out, int out_size)
 String convert base64.
 
SDB_EXPORT int base64Decode (const char *s, char *out, int out_size)
 Base64 convert string.
 
SDB_EXPORT int getEnBase64Size (int size)
 Get string convert base64 need size.
 
SDB_EXPORT int getDeBase64Size (const char *s)
 Get base64 convert string need size.
 

Detailed Description

Encode binary data using printable characters.

Function Documentation

int base64Decode ( const char *  s,
char *  out,
int  out_size 
)

Base64 convert string.

Parameters
[in]sInput string
[in]out_sizeThe size of the buffer that 'out' pointing to , make sure it's large enough
[out]outOutput string
Returns
If successful return the length of string,else return 0
char *str = "aGVsbG8gd29ybGQ=" ;
int len = getDeBase64Size ( str ) ;
char *out = (char *)malloc( len ) ;
memset( out, 0, len ) ;
base64Decode( str, out, len ) ;
printf( "out is: %s\n", out ) ;
free( out ) ;
SDB_EXTERN_C_STARTint base64Encode ( const char *  s,
int  in_size,
char *  out,
int  out_size 
)

String convert base64.

Parameters
[in]sInput buffer
[in]in_sizeInput buffer size
[in]out_sizeThe size of the buffer that 'out' pointing to , make sure it's large enough
[out]outOutput string
Returns
If successful return the length of base64,else return 0
char *str = "hello world" ;
int strLen = strlen( str ) ;
int len = getEnBase64Size ( strLen ) ;
char *out = (char *)malloc( len ) ;
memset( out, 0, len ) ;
base64Encode( str, strLen, out, len ) ;
printf( "out is: %s\n", out ) ;
free( out ) ;
int getDeBase64Size ( const char *  s)

Get base64 convert string need size.

Parameters
[in]sBase64
Returns
String length + 1
int getEnBase64Size ( int  size)

Get string convert base64 need size.

Parameters
[in]sizeoriginal data size
Returns
Base64 length + 1