{"id":21362749,"url":"https://github.com/protoncr/crypto","last_synced_at":"2025-07-13T03:31:22.745Z","repository":{"id":91428154,"uuid":"242426903","full_name":"protoncr/crypto","owner":"protoncr","description":"Pure Crystal implementations of various Cryptography algorithms","archived":false,"fork":false,"pushed_at":"2023-11-16T01:05:24.000Z","size":221,"stargazers_count":9,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-05-02T02:13:34.274Z","etag":null,"topics":["aes-256","aes-cbc","aes-ctr","aes-encryption","aes-ige","cryptography","crystal","crystal-lang","telegram"],"latest_commit_sha":null,"homepage":null,"language":"Crystal","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/protoncr.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}},"created_at":"2020-02-22T23:30:24.000Z","updated_at":"2023-11-16T01:05:28.000Z","dependencies_parsed_at":"2023-11-16T02:24:56.832Z","dependency_job_id":"2952db6a-396a-4fb8-8485-1abd416be512","html_url":"https://github.com/protoncr/crypto","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/protoncr%2Fcrypto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/protoncr%2Fcrypto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/protoncr%2Fcrypto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/protoncr%2Fcrypto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/protoncr","download_url":"https://codeload.github.com/protoncr/crypto/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225850152,"owners_count":17534067,"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":["aes-256","aes-cbc","aes-ctr","aes-encryption","aes-ige","cryptography","crystal","crystal-lang","telegram"],"created_at":"2024-11-22T06:15:24.287Z","updated_at":"2024-11-22T06:15:35.371Z","avatar_url":"https://github.com/protoncr.png","language":"Crystal","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Crypto Crystal\n\n![Specs](https://github.com/protoncr/crypto/workflows/Specs/badge.svg)\n\nPure Crystal port of [pyrogram/tgcrpto](https://github.com/pyrogram/tgcrpto). Implements various Cryptograpgy algorithms that are especially usefull for Telegram's MTPtoto protocol.\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n   ```yaml\n   dependencies:\n     crypto:\n       github: watzon/crypto\n   ```\n\n2. Run `shards install`\n\n## API\n\n```crystal\nmodule Crypto\n  module AES\n    def self.create_encryption_key(key : Bytes) : Slice(UInt32)\n    def self.create_decryption_key(key : Bytes) : Slice(UInt32)\n    def self.encrypt(data : Bytes, key : Indexable(UInt32)) : Bytes\n    def self.decrypt(data : Bytes, key : Indexable(UInt32)) : Bytes\n  end\n\n  module CBC\n    def self.encrypt(data : Bytes, key : Bytes, iv : Bytes) : Bytes\n    def self.decrypt(data : Bytes, key : Bytes, iv : Bytes) : Bytes\n  end\n\n  module CTR\n    def self.xcrypt(data : Bytes, key : Bytes, iv : Bytes, state : Bytes = [0_u8]) : Bytes\n  end\n\n  module IGE\n    def self.encrypt(data : Bytes, key : Bytes, iv : Bytes) : Bytes\n    def self.decrypt(data : Bytes, key : Bytes, iv : Bytes) : Bytes\n  end\n\n  module Padding\n    def self.pkcs7(buffer : Bytes, block_size : Int)\n  end\nend\n```\n\n## Usage\n\n### IGE Mode\n\n**Note:** Data must be padded to match a multiple of the block size `AES::BLOCK_SIZE`.\n\n```crystal\nrequire \"crypto\"\n\nrandom = Random.new\n\n# 10 MB of random data + 7 bytes to show padding\ndata = random.random_bytes(10 * 1024 * 1024 + 7)\n\nkey = random.random_bytes(32) # Random key\niv = random.random_bytes(32) # Random iv\n\n# Pad the data using PKCS7\ndata = Crypto::Padding.pkcs7(data, Crypto::AES::BLOCK_SIZE)\n\nencrypted = Crypto::IGE.encrypt(data, key, iv)\ndecrypted = Crypto::IGE.decrypt(encrypted, key, iv)\n\nputs data == decrypted\n# =\u003e true\n```\n\n### CTR Mode\n\n```crystal\nrequire \"crypto\"\n\nrandom = Random.new\n\n# 10 MB of random data + 7 bytes to show padding\ndata = random.random_bytes(10 * 1024 * 1024 + 7)\n\nkey = random.random_bytes(32) # Random key\niv = random.random_bytes(16) # Random iv\n\n# Pad the data using PKCS7\ndata = Crypto::Padding.pkcs7(data, Crypto::AES::BLOCK_SIZE)\n\nencrypted = Crypto::CTR.xcrypt(data, key, iv)\ndecrypted = Crypto::CTR.xcrypt(encrypted, key, iv)\n\nputs data == decrypted\n```\n\n### CBC Mode\n\n**Note:** Data must be padded to match a multiple of the block size `AES::BLOCK_SIZE`.\n\n```crystal\nrequire \"crypto\"\n\nrandom = Random.new\n\n# 10 MB of random data + 7 bytes to show padding\ndata = random.random_bytes(10 * 1024 * 1024 + 7)\n\nkey = random.random_bytes(32) # Random key\niv = random.random_bytes(16) # Random iv\n\n# Pad the data using PKCS7\ndata = Crypto::Padding.pkcs7(data, Crypto::AES::BLOCK_SIZE)\n\nencrypted = Crypto::CBC.encrypt(data, key, iv)\ndecrypted = Crypto::CBC.decrypt(encrypted, key, iv)\n\nputs data == decrypted\n```\n\n## Roadmap\n\n- [ ] Cipher Based\n  - [ ] AES\n    - [ ] 128\n    - [ ] 192\n    - [x] 256\n  - [ ] CBC\n    - [ ] 128\n    - [ ] 192\n    - [x] 256\n  - [ ] CTR\n    - [ ] 128\n    - [ ] 192\n    - [x] 256\n  - [ ] IGE\n    - [ ] 128\n    - [ ] 192\n    - [x] 256\n- [x] Public Key Cryptography\n  - [x] RSA\n- Hashing\n  - [ ] Blake\n    - [x] Blake2b\n    - [ ] Blake2s\n    - [ ] Blake3\n    - [ ] Argon2\n- [ ] Key Derivation Functions\n  - [ ] KDF\n    - [ ] PBKDF2\n- [ ] More?\n\n## Contributing\n\n1. Fork it (\u003chttps://github.com/watzon/crypto/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## Contributors\n\n- [Chris Watson](https://github.com/watzon) - creator and maintainer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprotoncr%2Fcrypto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprotoncr%2Fcrypto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprotoncr%2Fcrypto/lists"}