libb64下载地址http://sourceforge.net/projects/libb64
以下为Demo
libb64_demo.c
#include <stdio.h> #include <string.h> #include <libb64/cencode.h> #include <libb64/cdecode.h> void base64EncodeString(const char *textToEncode, char *buffer); void base64DecodeString(const char *codeToDecode, char *buffer); void base64EncodeFile(FILE *fileToEncode, FILE *encodedFile); void base64DecodeFile(FILE *encodedFile, FILE *decodedFile); int main() { const char *text = "Matt Damon"; char buffer[1000]; base64EncodeString(text, buffer); printf("%s", buffer); const char *code = "R29vZCBXaWxsIEh1bnRpbmc="; base64DecodeString(code, buffer); printf("%s ", buffer); const char *inputFilename = "易语言5.2修正版.rar"; FILE *inputFile = fopen(inputFilename, "rb"); if (inputFile) { const char *encodedFilename = "易语言5.2修正版.rar.txt"; FILE *encodedFile = fopen(encodedFilename, "wb"); if (encodedFile) { base64EncodeFile(inputFile, encodedFile); fclose(encodedFile); } else printf("Cannot open file: %s ", encodedFile); fclose(inputFile); } else printf("Cannot open file: %s ", inputFilename); const char *encodedFilename = "360DrvMgrInstaller_net.exe.txt"; FILE *encodedFile = fopen(encodedFilename, "rb"); if (encodedFile) { const char *decodedFilename = "360DrvMgrInstaller_net"; FILE *decodedFile = fopen(decodedFilename, "wb"); if (decodedFile) { base64DecodeFile(encodedFile, decodedFile); fclose(decodedFile); } else printf("Cannot open file: %s ", decodedFile); fclose(encodedFile); } else printf("Cannot open file: %s ", encodedFilename); system("pause"); return 0; } void base64EncodeString(const char *textToEncode, char *buffer) { base64_encodestate state; base64_init_encodestate(&state); int numberOfBytesEncoded = base64_encode_block(textToEncode, strlen(textToEncode), buffer, &state); numberOfBytesEncoded += base64_encode_blockend(buffer + numberOfBytesEncoded, &state); buffer[numberOfBytesEncoded] = '