{"id":13552438,"url":"https://github.com/leocavalcante/encrypt","last_synced_at":"2025-05-16T08:06:41.098Z","repository":{"id":32684254,"uuid":"139615853","full_name":"leocavalcante/encrypt","owner":"leocavalcante","description":"🔒 A set of high-level APIs over PointyCastle for two-way cryptography.","archived":false,"fork":false,"pushed_at":"2024-03-01T18:45:34.000Z","size":148,"stargazers_count":360,"open_issues_count":88,"forks_count":149,"subscribers_count":9,"default_branch":"5.x","last_synced_at":"2025-04-08T20:18:01.621Z","etag":null,"topics":["aes","cipher","cryptography","encryption","rsa","salsa20","secure-random-generator"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leocavalcante.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2018-07-03T17:20:58.000Z","updated_at":"2025-02-28T23:56:17.000Z","dependencies_parsed_at":"2024-01-19T07:02:59.361Z","dependency_job_id":"77fdf214-e72b-42d8-9229-e46419b0b918","html_url":"https://github.com/leocavalcante/encrypt","commit_stats":{"total_commits":113,"total_committers":22,"mean_commits":5.136363636363637,"dds":"0.23008849557522126","last_synced_commit":"06af93a351be539207dc8f7f5a71517aea4b1ca0"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leocavalcante%2Fencrypt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leocavalcante%2Fencrypt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leocavalcante%2Fencrypt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leocavalcante%2Fencrypt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leocavalcante","download_url":"https://codeload.github.com/leocavalcante/encrypt/tar.gz/refs/heads/5.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254493378,"owners_count":22080126,"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","cipher","cryptography","encryption","rsa","salsa20","secure-random-generator"],"created_at":"2024-08-01T12:02:03.989Z","updated_at":"2025-05-16T08:06:36.089Z","avatar_url":"https://github.com/leocavalcante.png","language":"Dart","funding_links":["https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=E4F45BFVMFVQW"],"categories":["Dart"],"sub_categories":[],"readme":"# encrypt\n\n[![Pub Package](https://img.shields.io/pub/v/encrypt.svg)](https://pub.dartlang.org/packages/encrypt)\n[![Dart CI](https://github.com/leocavalcante/encrypt/actions/workflows/dart.yaml/badge.svg)](https://github.com/leocavalcante/encrypt/actions/workflows/dart.yaml)\n[![Donate](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=E4F45BFVMFVQW)\n\nA set of high-level APIs over PointyCastle for two-way cryptography.\n\n\u003e Looking for password hashing? Please, visit [password](https://github.com/leocavalcante/password-dart).\n\n### Secure random\n\nYou can generate cryptographically secure random keys and IVs for you project.\n\nActivate the encrypt package:\n\n```bash\npub global activate encrypt\n```\n\nThen use the `secure-random` command-line tool:\n\n```bash\n$ secure-random\nCBoaDQIQAgceGg8dFAkMDBEOECEZCxgMBiAUFQwKFhg=\n```\n\nYou can set the length and the base output.\n\n```bash\n$ secure-random --help\n-l, --length       The length of the bytes\n                   (defaults to \"32\")\n\n-b, --base         Bytes represented as base 64 or base 16 (Hexdecimal)\n                   (defaults to \"64\")\n\n-h, --[no-]help    Show this help message\n```\n\n## Algorithms\n\nCurrent status is:\n\n- AES with PKCS7 padding\n- RSA with PKCS1 and OAEP encoding\n- Salsa20\n\n### Signing\n\n- SHA256 with RSA\n\n## Usage\n\n### Symmetric\n\n#### AES\n\n```dart\nimport 'package:encrypt/encrypt.dart';\n\nvoid main() {\n  final plainText = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit';\n  final key = Key.fromUtf8('my 32 length key................');\n  final iv = IV.fromLength(16);\n\n  final encrypter = Encrypter(AES(key));\n\n  final encrypted = encrypter.encrypt(plainText, iv: iv);\n  final decrypted = encrypter.decrypt(encrypted, iv: iv);\n\n  print(decrypted); // Lorem ipsum dolor sit amet, consectetur adipiscing elit\n  print(encrypted.base64); // R4PxiU3h8YoIRqVowBXm36ZcCeNeZ4s1OvVBTfFlZRdmohQqOpPQqD1YecJeZMAop/hZ4OxqgC1WtwvX/hP9mw==\n}\n```\n\n##### Modes of operation\n\nDefault mode is SIC `AESMode.sic`, you can override it using the `mode` named parameter:\n\n```dart\nfinal encrypter = Encrypter(AES(key, mode: AESMode.cbc));\n```\n\n###### Supported modes are:\n\n- CBC `AESMode.cbc`\n- CFB-64 `AESMode.cfb64`\n- CTR `AESMode.ctr`\n- ECB `AESMode.ecb`\n- OFB-64/GCTR `AESMode.ofb64Gctr`\n- OFB-64 `AESMode.ofb64`\n- SIC `AESMode.sic`\n\n##### No/zero padding\n\nTo remove padding, pass `null` to the `padding` named parameter on the constructor:\n\n```dart\nfinal encrypter = Encrypter(AES(key, mode: AESMode.cbc, padding: null));\n```\n\n#### Salsa20\n\n```dart\nimport 'package:encrypt/encrypt.dart';\n\nvoid main() {\n  final plainText = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit';\n  final key = Key.fromLength(32);\n  final iv = IV.fromLength(8);\n  final encrypter = Encrypter(Salsa20(key));\n\n  final encrypted = encrypter.encrypt(plainText, iv: iv);\n  final decrypted = encrypter.decrypt(encrypted, iv: iv);\n\n  print(decrypted); // Lorem ipsum dolor sit amet, consectetur adipiscing elit\n  print(encrypted.base64); // CR+IAWBEx3sA/dLkkFM/orYr9KftrGa7lIFSAAmVPbKIOLDOzGwEi9ohstDBqDLIaXMEeulwXQ==\n}\n```\n\n#### [Fernet](https://github.com/fernet/spec/blob/master/Spec.md)\n\n```dart\nimport 'package:encrypt/encrypt.dart';\nimport 'dart:convert';\n\nvoid main() {\n  final plainText = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit';\n  final key = Key.fromUtf8('my32lengthsupersecretnooneknows1');\n\n  final b64key = Key.fromUtf8(base64Url.encode(key.bytes).substring(0,32));\n  // if you need to use the ttl feature, you'll need to use APIs in the algorithm itself\n  final fernet = Fernet(b64key);\n  final encrypter = Encrypter(fernet);\n\n  final encrypted = encrypter.encrypt(plainText);\n  final decrypted = encrypter.decrypt(encrypted);\n\n  print(decrypted); // Lorem ipsum dolor sit amet, consectetur adipiscing elit\n  print(encrypted.base64); // random cipher text\n  print(fernet.extractTimestamp(encrypted.bytes)); // unix timestamp\n}\n```\n\n### Asymmetric\n\n#### RSA\n\n```dart\nimport 'dart:io';\nimport 'package:encrypt/encrypt.dart';\nimport 'package:pointycastle/asymmetric/api.dart';\n\nvoid main() {\n  final publicKey = await parseKeyFromFile\u003cRSAPublicKey\u003e('test/public.pem');\n  final privKey = await parseKeyFromFile\u003cRSAPrivateKey\u003e('test/private.pem');\n\n  final plainText = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit';\n  final encrypter = Encrypter(RSA(publicKey: publicKey, privateKey: privKey));\n\n  final encrypted = encrypter.encrypt(plainText);\n  final decrypted = encrypter.decrypt(encrypted);\n\n  print(decrypted); // Lorem ipsum dolor sit amet, consectetur adipiscing elit\n  print(encrypted.base64); // kO9EbgbrSwiq0EYz0aBdljHSC/rci2854Qa+nugbhKjidlezNplsEqOxR+pr1RtICZGAtv0YGevJBaRaHS17eHuj7GXo1CM3PR6pjGxrorcwR5Q7/bVEePESsimMbhHWF+AkDIX4v0CwKx9lgaTBgC8/yJKiLmQkyDCj64J3JSE=\n}\n```\n\n### Signature and verification\n\n#### RSA\n\n```dart\n final publicKey = await parseKeyFromFile\u003cRSAPublicKey\u003e('test/public.pem');\n final privateKey = await parseKeyFromFile\u003cRSAPrivateKey\u003e('test/private.pem');\n final signer = Signer(RSASigner(RSASignDigest.SHA256, publicKey: publicKey, privateKey: privateKey));\n\n print(signer.sign('hello world').base64);\n print(signer.verify64('hello world', 'jfMhNM2v6hauQr6w3ji0xNOxGInHbeIH3DHlpf2W3vmSMyAuwGHG0KLcunggG4XtZrZPAib7oHaKEAdkHaSIGXAtEqaAvocq138oJ7BEznA4KVYuMcW9c8bRy5E4tUpikTpoO+okHdHr5YLc9y908CAQBVsfhbt0W9NClvDWegs='));\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleocavalcante%2Fencrypt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleocavalcante%2Fencrypt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleocavalcante%2Fencrypt/lists"}