@ -44,6 +44,7 @@ BOOL
Base64Encode ( const char * input , int input_len , char * * output )
Base64Encode ( const char * input , int input_len , char * * output )
{
{
DWORD output_len ;
DWORD output_len ;
DWORD flags = CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF ;
if ( input_len = = 0 )
if ( input_len = = 0 )
{
{
@ -52,7 +53,7 @@ Base64Encode(const char *input, int input_len, char **output)
return TRUE ;
return TRUE ;
}
}
if ( ! CryptBinaryToStringA ( ( const BYTE * ) input , ( DWORD ) input_len ,
if ( ! CryptBinaryToStringA ( ( const BYTE * ) input , ( DWORD ) input_len ,
CRYPT_STRING_BASE64 , NULL , & output_len ) | | output_len = = 0 )
flags , NULL , & output_len ) | | output_len = = 0 )
{
{
# ifdef DEBUG
# ifdef DEBUG
PrintDebug ( L " Error in CryptBinaryToStringA: input = '%.*S' " , input_len , input ) ;
PrintDebug ( L " Error in CryptBinaryToStringA: input = '%.*S' " , input_len , input ) ;
@ -65,7 +66,7 @@ Base64Encode(const char *input, int input_len, char **output)
return FALSE ;
return FALSE ;
if ( ! CryptBinaryToStringA ( ( const BYTE * ) input , ( DWORD ) input_len ,
if ( ! CryptBinaryToStringA ( ( const BYTE * ) input , ( DWORD ) input_len ,
CRYPT_STRING_BASE64 , * output , & output_len ) )
flags , * output , & output_len ) )
{
{
# ifdef DEBUG
# ifdef DEBUG
PrintDebug ( L " Error in CryptBinaryToStringA: input = '%.*S' " , input_len , input ) ;
PrintDebug ( L " Error in CryptBinaryToStringA: input = '%.*S' " , input_len , input ) ;
@ -74,12 +75,6 @@ Base64Encode(const char *input, int input_len, char **output)
* output = NULL ;
* output = NULL ;
return FALSE ;
return FALSE ;
}
}
/* Trim trailing "\r\n" manually.
Actually they can be stripped by adding CRYPT_STRING_NOCRLF to dwFlags ,
but Windows XP / 2003 does not support this flag . */
if ( output_len > 1 & & ( * output ) [ output_len - 1 ] = = ' \x0A '
& & ( * output ) [ output_len - 2 ] = = ' \x0D ' )
( * output ) [ output_len - 2 ] = 0 ;
return TRUE ;
return TRUE ;
}
}