{"id":22210525,"url":"https://github.com/nicolab/crystal-crypt","last_synced_at":"2026-03-08T00:31:22.677Z","repository":{"id":78147745,"uuid":"311093534","full_name":"Nicolab/crystal-crypt","owner":"Nicolab","description":":gem: Cryptographic utilities made easy for Crystal lang.","archived":false,"fork":false,"pushed_at":"2021-03-26T18:08:21.000Z","size":94,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-27T10:42:41.837Z","etag":null,"topics":["cipher","crypto","cryptography","crystal","crystal-lang","decrypt","encode","encrypt","signature"],"latest_commit_sha":null,"homepage":"https://nicolab.github.io/crystal-crypt/","language":"Crystal","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Nicolab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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,"zenodo":null},"funding":{"github":"Nicolab","custom":"https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=PGRH4ZXP36GUC"}},"created_at":"2020-11-08T15:30:56.000Z","updated_at":"2023-03-29T15:21:19.000Z","dependencies_parsed_at":"2023-05-04T17:41:38.036Z","dependency_job_id":null,"html_url":"https://github.com/Nicolab/crystal-crypt","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/Nicolab/crystal-crypt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nicolab%2Fcrystal-crypt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nicolab%2Fcrystal-crypt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nicolab%2Fcrystal-crypt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nicolab%2Fcrystal-crypt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Nicolab","download_url":"https://codeload.github.com/Nicolab/crystal-crypt/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nicolab%2Fcrystal-crypt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30238848,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-08T00:30:53.000Z","status":"ssl_error","status_checked_at":"2026-03-08T00:30:44.061Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["cipher","crypto","cryptography","crystal","crystal-lang","decrypt","encode","encrypt","signature"],"created_at":"2024-12-02T20:12:59.399Z","updated_at":"2026-03-08T00:31:22.666Z","avatar_url":"https://github.com/Nicolab.png","language":"Crystal","funding_links":["https://github.com/sponsors/Nicolab","https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=PGRH4ZXP36GUC"],"categories":[],"sub_categories":[],"readme":"# Crypt\n\n[![CI Status](https://github.com/Nicolab/crystal-crypt/workflows/CI/badge.svg?branch=master)](https://github.com/Nicolab/crystal-crypt/actions) [![GitHub release](https://img.shields.io/github/release/Nicolab/crystal-crypt.svg)](https://github.com/Nicolab/crystal-crypt/releases) [![Docs](https://img.shields.io/badge/docs-available-brightgreen.svg)](https://nicolab.github.io/crystal-crypt/)\n\nCryptographic utilities made easy for [Crystal lang](https://crystal-lang.org).\n\nThis module provides cryptographic features, with abstractions on top of OpenSSL\nand Crypto (included in the Crystal standard-library).\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n```yaml\ndependencies:\n  crypt:\n    github: nicolab/crystal-crypt\n```\n\n2. Run `shards install`\n\n## Usage\n\nTo optimize the size of the final binary, features are decoupled,\nso each module must be included when you need it.\n\n### OpenSSL Cipher: Encrypt / Decrypt\n\n\u003e [API doc: Crypt::Crypter](https://nicolab.github.io/crystal-crypt/Crypt/Crypter.html)\n\n```crystal\nrequire \"crypt\"\nrequire \"crypt/crypter\"\nrequire \"crypt/random\"\n\ndata = \"super secret data\"\nsecret = Crypt.random_string(32)\ncrypter = Crypt::Crypter.new(secret)\n\n# Data encrypted\nencrypted = crypter.encrypt(data)\n\n# Data decrypted\ndecrypted_bytes = crypter.decrypt(encrypted)\n\n# Decrypted data (Bytes)\nputs decrypted_bytes\n\n# Convert Bytes to String\nputs String.new(decrypted_bytes)\n```\n\n#### With signature\n\nEncrypt with a crypto signature:\n\n```crystal\nrequire \"crypt\"\nrequire \"crypt/crypter\"\nrequire \"crypt/random\"\n\ndata = \"super secret data\"\nsecret = Crypt.random_string(32)\ncrypter = Crypt::Crypter.new(secret)\n\n# Data encrypted and signed\nencrypted = crypter.encrypt(data, :sign)\n\n# Data verified and decrypted\ndecrypted_bytes = crypter.decrypt(encrypted, :sign)\n\n# Decrypted data (Bytes)\nputs decrypted_bytes\n\n# Convert Bytes to String\nputs String.new(decrypted_bytes)\n```\n\n### Signer\n\nSign and verify given data.\n\n```crystal\nrequire \"crypt\"\nrequire \"crypt/signer\"\n\ndata = \"Hello Crystal!\"\nsecret = \"super secret\"\nsigner = Crypt::Signer.new(secret)\n\n# Sign the data\nsigned_data = signer.sign(data)\n\n# =\u003e Encoded String, URL and filename safe alphabet (RFC 4648).\nputs signed_data\n\n# Verify the data integrity and get it\nputs signer.verify(signed_data)         # =\u003e \"Hello Crystal!\"\nputs signer.verify(signed_data) == data # =\u003e true\n```\n\n\u003e [API doc: Crypt::Signer](https://nicolab.github.io/crystal-crypt/Crypt/Signer.html)\n\n### Bcrypt password\n\nGenerate, read and verify `Crypto::Bcrypt` hashes:\n\n```crystal\nrequire \"crypt\"\nrequire \"crypt/bcrypt\"\n\npassword = Crypt.create_bcrypt_password(\"super secret\", cost: 10)\n# =\u003e $2a$10$rI4xRiuAN2fyiKwynO6PPuorfuoM4L2PVv6hlnVJEmNLjqcibAfHq\n\npassword.verify(\"wrong secret\") # =\u003e false\npassword.verify(\"super secret\") # =\u003e true\n```\n\n\u003e [API doc: Crypt.create_bcrypt_password](https://nicolab.github.io/crystal-crypt/Crypt.html#create_bcrypt_password)\n\n---\n\nLoads a `Bcrypt` password hash.\n\n```crystal\nrequire \"crypt\"\nrequire \"crypt/bcrypt\"\n\npassword = Crypt.load_bcrypt_password(\n  \"$2a$10$X6rw/jDiLBuzHV./JjBNXe8/Po4wTL0fhdDNdAdjcKN/Fup8tGCya\"\n)\npassword.version # =\u003e \"2a\"\npassword.salt    # =\u003e \"X6rw/jDiLBuzHV./JjBNXe\"\npassword.digest  # =\u003e \"8/Po4wTL0fhdDNdAdjcKN/Fup8tGCya\"\n\n# password.verify(\"some secret\")\n```\n\n\u003e [API doc: Crypt.load_bcrypt_password](https://nicolab.github.io/crystal-crypt/Crypt.html#load_bcrypt_password)\n\n### Secure random\n\n```crystal\nrequire \"crypt\"\nrequire \"crypt/random\"\n```\n\nSee API doc:\n\n* [API doc: Crypt.random_string](https://nicolab.github.io/crystal-crypt/Crypt.html#random_string)\n* [API doc: Crypt.random_bytes](https://nicolab.github.io/crystal-crypt/Crypt.html#random_bytes)\n* [API doc: Crypt.random_bytes_string](https://nicolab.github.io/crystal-crypt/Crypt.html#random_bytes_string)\n\n### Key derivation\n\nKey derivation PKCS5/PBKDF2 (Password-Based Key Derivation Function 2)\n\n```crystal\nrequire \"crypt\"\nrequire \"crypt/key-deriv\"\nrequire \"crypt/random\"\n\npassword = \"My password\"\nsalt = Crypt.random_string(16)\n\n# key size: 64\nCrypt.key_deriv(password, salt)\n\n# key size: 10\nCrypt.key_deriv(password, salt, key_size: 10)\n\n# iteration: 2000\nCrypt.key_deriv(password, salt, iter: 2000)\n\n# algo: sha256\nCrypt.key_deriv(password, salt, algo: :sha256)\n```\n\n\u003e [API doc: Crypt.key_deriv](https://nicolab.github.io/crystal-crypt/Crypt.html#key_deriv)\n\n## Contributing\n\n1. Fork it (\u003chttps://github.com/nicolab/crystal-crypt/fork\u003e)\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n### Development\n\nOne line:\n\n```sh\n./scripts/develop\n```\n\nor splitted:\n\nTerminal 1:\n\n```sh\ndocker-compose up\n```\n\nTerminal 2:\n\n```sh\n# host\ndocker-compose exec app bash\n\n# container\njust develop\n```\n\nWhen you are done, clean and check the code:\n\n```sh\n# container\njust format\n\n# host\n./scripts/check\n```\n\n## LICENSE\n\n[MIT](https://github.com/Nicolab/crystal-crypt/blob/master/LICENSE) (c) 2020, Nicolas Talle.\n\n## Author\n\n| [![Nicolas Tallefourtane - Nicolab.net](https://www.gravatar.com/avatar/d7dd0f4769f3aa48a3ecb308f0b457fc?s=64)](https://github.com/sponsors/Nicolab) |\n|---|\n| [Nicolas Talle](https://github.com/sponsors/Nicolab) |\n| [![Make a donation via Paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=PGRH4ZXP36GUC) |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicolab%2Fcrystal-crypt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnicolab%2Fcrystal-crypt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicolab%2Fcrystal-crypt/lists"}