{"id":20566290,"url":"https://github.com/telkomdev/cb64","last_synced_at":"2025-12-04T17:06:49.594Z","repository":{"id":107251237,"uuid":"423187171","full_name":"telkomdev/cb64","owner":"telkomdev","description":"A Header Only Base64 Encoder and Decoder implementation in C","archived":false,"fork":false,"pushed_at":"2022-11-14T13:42:33.000Z","size":74,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-16T20:19:11.205Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/telkomdev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-31T15:34:33.000Z","updated_at":"2022-12-06T11:38:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"f4679291-5c08-4d73-9e6d-63bf350e127d","html_url":"https://github.com/telkomdev/cb64","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/telkomdev%2Fcb64","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/telkomdev%2Fcb64/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/telkomdev%2Fcb64/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/telkomdev%2Fcb64/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/telkomdev","download_url":"https://codeload.github.com/telkomdev/cb64/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242179259,"owners_count":20084940,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T04:40:58.996Z","updated_at":"2025-12-04T17:06:44.546Z","avatar_url":"https://github.com/telkomdev.png","language":"C","readme":"## cb64\n\nBase64 Encoding implementation in C Programming Language\n\n[![cb64 CI](https://github.com/telkomdev/cb64/actions/workflows/ci.yml/badge.svg)](https://github.com/telkomdev/cb64/actions/workflows/ci.yml)\n\nSpec: https://datatracker.ietf.org/doc/html/rfc4648#page-5\n\n### Header only\nSo just copy [`cb64.h`](https://github.com/telkomdev/cb64/blob/master/b64/cb64.h) to your project, and you ready to go\n\n\n### Building Example\n\n```shell\n$ mkdir build\n$ cd build/\n$ cmake ..\n$ make\n$ cd ..\n```\n\nRun example binary\n```shell\n$ ./bin/cb64 ./testdata/octocat.png\n```\n\n### Usage\n\n#### Encoding\n\nEncode and Decode Text\n```c\n#include \u003cstdio.h\u003e\n#include \u003cstring.h\u003e\n#include \"cb64.h\"\n\n#define EXIT_ERR(msg) { \\\n        printf(\"%s\\n\", msg); \\\n        exit(-1); \\\n    }\n\nint get_file_size(size_t* size, FILE* f);\n\nint main(int argc, char** argv) {\n\n    unsigned char* input = \"wur0\";\n    unsigned char* dst = NULL;\n    size_t dst_size = 0;\n    int encode_ok = encode_b64(input, 0, \u0026dst, \u0026dst_size);\n    if (encode_ok != 0)\n        EXIT_ERR(\"error encode text to base64\");\n\n    printf(\"%s\\n\", dst);\n    printf(\"%lu\\n\", dst_size);\n\n    unsigned char* dst_decode = NULL;\n    size_t dst_size_decode = 0;\n    int decode_ok = decode_b64(dst, 0, \u0026dst_decode, \u0026dst_size_decode);\n    if (decode_ok != 0)\n        EXIT_ERR(\"error decode text to base64\");\n\n    printf(\"%s\\n\", dst_decode);\n    printf(\"%lu\\n\", dst_size_decode);\n\n\n    free(dst);\n    free(dst_decode);\n    return 0;\n}\n```\n\nEncode File\n```c\n#include \u003cstdio.h\u003e\n#include \u003cstring.h\u003e\n#include \"cb64.h\"\n\n#define EXIT_ERR(msg) { \\\n        printf(\"%s\\n\", msg); \\\n        exit(-1); \\\n    }\n\nint get_file_size(size_t* size, FILE* f);\n\nint main(int argc, char** argv) \n{\n\n    // encode file to base64\n\n    if (argc \u003c 2)\n    {\n        EXIT_ERR(\"required filename\");\n    }\n\n    char* filename = argv[1];\n    char* filename_out = \"../testdata/out.txt\";\n\n    printf(\"filename : %s\\n\", filename);\n\n    FILE* file;\n    FILE* file_out;\n\n    file = fopen(filename, \"rb\");\n    if (file == NULL)\n    {\n        EXIT_ERR(\"file not found\");\n    }\n\n    file_out = fopen(filename_out, \"wb\");\n\n    size_t file_size;\n    if (get_file_size(\u0026file_size, file) != 0)\n        EXIT_ERR(\"error get file size\");\n\n    printf(\"%lu\\n\", file_size);\n\n    unsigned char input[file_size+1];\n    unsigned char* dst = NULL;\n    size_t dst_size = 0;\n\n    fread(input, sizeof(char), file_size, file);\n    input[file_size] = '\\0';\n\n    int encode_ok = encode_b64(input, file_size, \u0026dst, \u0026dst_size);\n    if (encode_ok != 0)\n        EXIT_ERR(\"error encode text to base64\");\n\n    // printf(\"%s\\n\", dst);\n    fwrite(dst, 1, dst_size, file_out);\n\n    fclose(file);\n    fclose(file_out);\n    free(dst);\n\n    return 0;\n}\n\nint get_file_size(size_t* size, FILE* f)\n{\n    // goto the end of the file\n    if (fseek(f, 0L, SEEK_END) != 0)\n        return -1;\n\n    // get the current file position of the given stream.\n    *size = ftell(f);\n\n    // go back the start of the file\n    if (fseek(f, 0L, SEEK_SET) != 0)\n        return -1;\n    \n    return 0;\n}\n```\n\nDecode File from Base64 Text\n```c\n#include \u003cstdio.h\u003e\n#include \u003cstring.h\u003e\n#include \"cb64.h\"\n\n#define EXIT_ERR(msg) { \\\n        printf(\"%s\\n\", msg); \\\n        exit(-1); \\\n    }\n\nint get_file_size(size_t* size, FILE* f);\n\nint main(int argc, char** argv) \n{\n    char* filename = \"../testdata/haha.txt\";\n    char* filename_out = \"../testdata/out.png\";\n    FILE* file;\n    FILE* file_out;\n\n    file = fopen(filename, \"r\");\n    if (file == NULL)\n    {\n        EXIT_ERR(\"file not found\");\n    }\n\n    file_out = fopen(filename_out, \"wb\");\n\n    size_t file_size;\n    if (get_file_size(\u0026file_size, file) != 0)\n        EXIT_ERR(\"error get file size\");\n\n    printf(\"%lu\\n\", file_size);\n\n    unsigned char input[file_size+1];\n\n    unsigned char* dst_decode = NULL;\n    size_t dst_size_decode = 0;\n\n    fread(input, sizeof(char), file_size, file);\n    input[file_size] = '\\0';\n\n    int decode_ok = decode_b64(input, 0, \u0026dst_decode, \u0026dst_size_decode);\n    if (decode_ok != 0)\n        EXIT_ERR(\"error decode text to base64\");\n\n    printf(\"%s\\n\", dst_decode);\n\n    fwrite(dst_decode, 1, dst_size_decode, file_out);\n\n    free(dst_decode);\n    fclose(file);\n    fclose(file_out);\n    return 0;\n}\n\nint get_file_size(size_t* size, FILE* f)\n{\n    // goto the end of the file\n    if (fseek(f, 0L, SEEK_END) != 0)\n        return -1;\n\n    // get the current file position of the given stream.\n    *size = ftell(f);\n\n    // go back the start of the file\n    if (fseek(f, 0L, SEEK_SET) != 0)\n        return -1;\n    \n    return 0;\n}\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftelkomdev%2Fcb64","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftelkomdev%2Fcb64","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftelkomdev%2Fcb64/lists"}