{"id":16002875,"url":"https://github.com/soreing/rsa-cpp-encrypt","last_synced_at":"2025-03-27T11:32:15.396Z","repository":{"id":110409822,"uuid":"392678540","full_name":"Soreing/rsa-cpp-encrypt","owner":"Soreing","description":"Simple RSA key generation and encryption library for C++","archived":false,"fork":false,"pushed_at":"2023-04-04T00:38:20.000Z","size":30,"stargazers_count":15,"open_issues_count":2,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-23T17:45:27.447Z","etag":null,"topics":["big-integer","cpp","crypto","cryptography","montgomery-multiplication","rsa","rsa-encryption","x86"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Soreing.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-08-04T12:22:46.000Z","updated_at":"2025-03-02T08:08:03.000Z","dependencies_parsed_at":"2024-02-24T07:15:07.093Z","dependency_job_id":null,"html_url":"https://github.com/Soreing/rsa-cpp-encrypt","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/Soreing%2Frsa-cpp-encrypt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soreing%2Frsa-cpp-encrypt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soreing%2Frsa-cpp-encrypt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soreing%2Frsa-cpp-encrypt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Soreing","download_url":"https://codeload.github.com/Soreing/rsa-cpp-encrypt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245836327,"owners_count":20680355,"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":["big-integer","cpp","crypto","cryptography","montgomery-multiplication","rsa","rsa-encryption","x86"],"created_at":"2024-10-08T10:04:42.102Z","updated_at":"2025-03-27T11:32:15.391Z","avatar_url":"https://github.com/Soreing.png","language":"C++","readme":"# rsa-cpp-encrypt\n\n# Description\n\nrsa-cpp-encrypt is a simple textbook RSA library for C++. The library is capable of generating 2048 bit RSA key pairs, encrypting, decrypting and also exporting/importing keys in PKCS#1 format. The implementation uses [biging-x86cpp](https://github.com/Soreing/bigint-x86cpp/) and is only compatible with x86 architecture CPUs\n\n# Installation \nAdd the folders `bigint` and `rsa-crypt` from `/include` in your include path. If you want to compile the library from source, include `ASN1.cpp` and `RSACipher.cpp` from the `/src` folder. Alternatively, you can compile the source code to a static library and include it that way.\n\n# Usage\n## Creating an RSA Cipher\nTo create a cipher, you can provide a public or a private key. If you want to generate a new key, you can use the `genPrivKey()` function. The function generates a random key you can seed with the C `srand()` function.\n```c++\nsrand(1234);\nRSACipher rsa(genPrivKey());\n```\n\n## Importing Keys\nAlternatively, you can create an empty RSA cipher, then import a public or a private key. The import and export functions only take PKCS#1 format RSA keys.\n```c++\nRSACipher rsa;\nrsa.importPubKey(\n    \"-----BEGIN RSA PUBLIC KEY-----\\n\"\n    \"MIIBCgKCAQEAq ...... 7dcERQIDAQAB\"\n    \"\\n-----END RSA PUBLIC KEY-----\"\n);\n```\n\n```c++\nRSACipher rsa;\nrsa.importPrvKey(\n    \"-----BEGIN RSA PRIVATE KEY-----\\n\"\n    \"MIIEpQIBAAKCA ...... dMbKLovrxqU=\"\n    \"\\n-----END RSA PRIVATE KEY-----\"\n);\n```\n\n## Exporting Keys\nYou can export a private or a public key into a character array buffer. You also need to provide the size of the buffer. The key is exported in PKCS#1 format\n```c++\nchar buff[2048];\nrsa.exportPubKey(buff, 2048);\n\n// Prints PKCS#1 formatted Public Key\ncout \u003c\u003c buff \u003c\u003c endl;\n```\n\n## Encrypting and Decrypting\nOnce you have created an RSA cipher, you can encrypt or decrypt 256 bytes of data. For this, the cipher expects a 256 byte large Big Integer. The result of encryption and decryption is also a Big Integer.\n```c++\nBigInt\u003c256\u003e message(\"123456\");\nBigInt\u003c256\u003e ciphertext = rsa.encrypt(message);\nBigInt\u003c256\u003e plaintext  = rsa.decrypt(ciphertext);\n\ncout\u003c\u003c message \u003c\u003c \"\\n\\n\";\ncout\u003c\u003c ciphertext.toString(64) \u003c\u003c \"\\n\\n\";\ncout\u003c\u003c plaintext \u003c\u003c \"\\n\\n\";\n```\n```\nOutput:\n123456\n\nS12DtydRI2r72ouUWsHSVat5lfuU45bYVl+W3aPgcKnnlX05w2qmlgjN+MMsURnmA0/SAM+ZPvBej8Vvs3i0XwT5J6Q+qR6k7SQZ6qdPM8tiqaHeJ+9tVMLu+NJ4NTmtUypFxIufm0agvx3RyK4EmhOOw7dZC9CqadnAWxDYDpG6eVkH+PO2qUzxVddy4Iojj/29kjo2p3TzvSoE7lMoAT3trW3Er+vhjRpK/saFD8EnsTc//bfQ87EFUxt81p+e9uGiXz4Cd6aWUTXNypo3uy+VaLg9+9yQ1WVdxPrv/OMFNsE7XsFW9DgfZHGZy+4T0IekUvEjGf2+2b8ciYXpZA==\n\n123456\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoreing%2Frsa-cpp-encrypt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoreing%2Frsa-cpp-encrypt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoreing%2Frsa-cpp-encrypt/lists"}