{"id":19534967,"url":"https://github.com/newyaroslav/crypto-json","last_synced_at":"2026-05-15T06:37:29.846Z","repository":{"id":162735314,"uuid":"353804167","full_name":"NewYaroslav/crypto-json","owner":"NewYaroslav","description":"C ++ library for JSON encryption with COMMENTS","archived":false,"fork":false,"pushed_at":"2021-04-06T23:07:10.000Z","size":22110,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-08T17:52:35.609Z","etag":null,"topics":["cryptography","json","json-parser","strip-json-comments"],"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/NewYaroslav.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-04-01T19:21:54.000Z","updated_at":"2023-03-24T06:10:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"37c73f39-f498-4ca1-99e4-7a34862a9951","html_url":"https://github.com/NewYaroslav/crypto-json","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/NewYaroslav%2Fcrypto-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NewYaroslav%2Fcrypto-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NewYaroslav%2Fcrypto-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NewYaroslav%2Fcrypto-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NewYaroslav","download_url":"https://codeload.github.com/NewYaroslav/crypto-json/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240788773,"owners_count":19857699,"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":["cryptography","json","json-parser","strip-json-comments"],"created_at":"2024-11-11T02:16:43.010Z","updated_at":"2026-05-15T06:37:29.801Z","avatar_url":"https://github.com/NewYaroslav.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"![logo](doc/logo-mini.png)\n\n# crypto-json\nC ++ library for JSON encryption with COMMENTS\n\n## Описание\n\n**Проект находится в разработке**\n\nДанный проект, это редактор и библиотека, которые позволяют хранить данные JSON с комментариями в сжатом и зашифрованном виде.\nПроект создан на *C++11*.\n\n# Зачем?\n\nЗашифрованные и сжатые файлы JSON могут быть полезны для хранения конфигураций программ, которые нужно скрыть от пользователя.\nЭто могут быть лицензионные ключи, параметры авторизации, языковые настройки, тексты.\n\n## Редактор Сrypto JSON\n\nРедактор позволяет открывать, редактировать и сохранять файлы с *JSON* структурами. Файлы могут быть *сжаты*, *зашифрованы* или сжаты и зашифрованы сразу, а так же *иметь комментарии*.\nНо редактор позволяет работать и с обычными текстовыми файллами.\n\nПрограмму можно найти в архиве *bin.zip*.\n\n![logo](doc/example.png)\n\n*Главное окно*\n\n![logo](doc/example2.png)\n\n*Параметры кодирования файла*\n\n## JSON с комментариями\n\nДля очистики строковых данных, содержащих JSON данные с комментариями, используется функция:\n\n```cpp\nstd::string strip_json_comments(const std::string \u0026json_string, const bool with_whitespace = false)\n````\n\n* json_string \t\t-\tСтрока с JSON и комментариями\n* with_whitespace \t- \tФлаг включает замену комментариев пробелами (за исключением символа *\\n*)\n* Функция вернет очищенную от комментариев строку\n\nРеализацию функции *strip_json_comments* можно найти в файле *include\\crypto-json\\strip-json-comments.hpp*.\nФункция *strip_json_comments* переписана с JS на С++. За основу был взяд код проекта [strip-json-comments](https://github.com/sindresorhus/strip-json-comments).\n\nПример кода:\n\n```cpp\n#include \"../../include/crypto-json/strip-json-comments.hpp\"\n#include \"../../include/crypto-json/utilities.hpp\"\n\n//...\n\n\nstd::string src;\ncrypto_json::load_file(\"test.json\", src);\n    \nstd::string dst = crypto_json::strip_json_comments(src);\nstd::cout \u003c\u003c \"dst:\" \u003c\u003c std::endl \u003c\u003c dst \u003c\u003c std::endl;\n\nstd::string dst2 = crypto_json::strip_json_comments(src, true);\nstd::cout \u003c\u003c \"dst2:\" \u003c\u003c std::endl \u003c\u003c dst2 \u003c\u003c std::endl;\n```\n\nПример JSON с комментариями (взят от [сюда](https://github.com/spmbt/jsonComm)):\n\n```json\n//first line\n\n\t{\"aaa\": \"qwerty\",// \n\t\"bbb\": 1234 //comment (not pure JSON syntax)\n\t,\"ccc\": true # alternative comment style\n\t,\"dd\\\"d\":/*multiline\\\\\" comm\\\\ent*/ /*comm2\\\\*/null,\n\t\"ee//e\": \"example of any symbols in key including inactive comments\",\n\t\"multiline1\"/*: 1, //- example of multiline comments\n\t\"multiline2\": 2,\n\t\"multiline3\":= 1234,*/:[36.8,false/*,34*/,\n\t\t\"/**/\",[1,2,3,4,[//56789\n\t\t5,6,[[/*0*/7,{\"x\":/*xx*/\"x\"}],8]],{}]  ],\n\t\"mayBeAnyStructure\":{\"a\":1/**/,\"b\":2},\n\"lineEnd\\\\\\\\\":\"end\"\n}//after json\n\n/*2nd after*/  \n```\n\n## Библиотека\n\nДля работы с зашифрованными и сжатыми данными JSON существуют несколько функций. Пример ниже должен пояснить, как ими пользоваться:\n \n```cpp\n#include \u003ccrypto-json/crypto-json.hpp\u003e\n\n//...\n\n/* загрузим текст из файла test.json */\nstd::string src;\ncrypto_json::load_file(\"test.json\", src);\n\n/* настроим тип шифрования - алгоритм AES в режиме CFB, длина ключа 256 */\ncrypto_json::EncryptionAlgorithmType type = crypto_json::EncryptionAlgorithmType::USE_AES_CFB_256;\n\n/* создадим ключ и инициализирующий вектор длиной 256 */\nstd::array\u003cuint8_t, 32\u003e key;\nstd::array\u003cuint8_t, 32\u003e iv;\n\n/* для примера, зазадим случайный ключ и инициализирующий вектор */\ncrypto_json::generate_key_or_iv(key);\ncrypto_json::generate_key_or_iv(iv);\n\n/* преобразуем ключ и инициализирующий вектор в hex-строку и выведем на экран */\nstd::cout \u003c\u003c \"key:\" \u003c\u003c std::endl \u003c\u003c crypto_json::to_hex_string(key) \u003c\u003c std::endl;\nstd::cout \u003c\u003c \"iv:\" \u003c\u003c std::endl \u003c\u003c crypto_json::to_hex_string(iv) \u003c\u003c std::endl;\n\n/* преобразуем hex-строку в ключ и инициализирующий вектор */\nstd::array\u003cuint8_t, 32\u003e key2;\nstd::array\u003cuint8_t, 32\u003e iv2;\ncrypto_json::convert_hex_string_to_byte(crypto_json::to_hex_string(key), key2);\ncrypto_json::convert_hex_string_to_byte(crypto_json::to_hex_string(iv), iv2);\n\n/* зашифруем текст и сожмьем его при помощи алгоритма brotli */\nstd::string crypto_json_str = crypto_json::to_crypto_json(src, key, iv, type, true);\n\n/* сравним размеры зашифрованного текста и оригинального */\nstd::cout \u003c\u003c \"src size:\" \u003c\u003c src.size() \u003c\u003c std::endl;\nstd::cout \u003c\u003c \"crypto json size: \" \u003c\u003c crypto_json_str.size() \u003c\u003c std::endl;\n\n/* дешифруем crypto json */\nstd::string str = crypto_json::to_string(crypto_json_str, key, iv, type, true);\n\n/* дешифруем crypto json в класс json библиотеки nlohmann/json.hpp */\nnlohmann::json j = crypto_json::to_json(crypto_json_str, key, iv, type, true);\nstd::cout \u003c\u003c \"to json:\" \u003c\u003c std::endl \u003c\u003c j \u003c\u003c std::endl;\n\t\n/* зашифруем данные класса библиотеки nlohmann/json.hpp */ \nstd::string crypto_json_str2 = crypto_json::to_crypto_json(j, key, iv, type, true);\n```\n\n## Как подключить библиотеку и зависимости\n\nБиблиотека *crypto json* имеет следующие зависимости:\n\n* Библиотека для шифрования алгоритмом AES: https://github.com/SergeyBel/AES\n* Библиотека алгоритма сжатия brotli: https://github.com/google/brotli\n* Библиотека оболочка для алгоритма сжатия brotli: https://github.com/NewYaroslav/brotli-hpp\n* Библиотека для работы с JSON: https://github.com/nlohmann/json\n\nВсе указанные зависимости, как субмодули, добавлены в папку *lib*.\nЧтобы использовать библиотеки brotli и JSON, включите макросы:\n\n```cpp\nCRYPTO_JSON_USE_BROTLI\nCRYPTO_JSON_USE_NLOHMANN_JSON\n```\n\nБиблиотека *crypto json* является *header-only*. Для подключения *crypto json* в свой проект просто укажите путь к файлами *crypto json* и к файлам ее зависимостей, и добавьте заголовочный файл *crypto-json/crypto-json.hpp*.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnewyaroslav%2Fcrypto-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnewyaroslav%2Fcrypto-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnewyaroslav%2Fcrypto-json/lists"}