{"id":22807966,"url":"https://github.com/whitedg/mybatis-crypto","last_synced_at":"2025-06-29T07:36:01.818Z","repository":{"id":43141041,"uuid":"443736177","full_name":"WhiteDG/mybatis-crypto","owner":"WhiteDG","description":"🔐 A mybatis-based crypto plugin","archived":false,"fork":false,"pushed_at":"2024-09-19T09:55:12.000Z","size":145,"stargazers_count":74,"open_issues_count":6,"forks_count":20,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-22T12:32:34.929Z","etag":null,"topics":["crypto","mybatis","spring-boot","spring-starters"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WhiteDG.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":"2022-01-02T10:21:23.000Z","updated_at":"2025-02-26T08:10:11.000Z","dependencies_parsed_at":"2023-11-28T10:27:54.014Z","dependency_job_id":"55adb46a-6863-4d3b-8700-d1596ab06320","html_url":"https://github.com/WhiteDG/mybatis-crypto","commit_stats":{"total_commits":55,"total_committers":1,"mean_commits":55.0,"dds":0.0,"last_synced_commit":"ee364b1634d0b3ac547af7372d26d7af20254c48"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WhiteDG%2Fmybatis-crypto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WhiteDG%2Fmybatis-crypto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WhiteDG%2Fmybatis-crypto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WhiteDG%2Fmybatis-crypto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WhiteDG","download_url":"https://codeload.github.com/WhiteDG/mybatis-crypto/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245111952,"owners_count":20562512,"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":["crypto","mybatis","spring-boot","spring-starters"],"created_at":"2024-12-12T11:07:21.574Z","updated_at":"2025-03-23T14:10:37.983Z","avatar_url":"https://github.com/WhiteDG.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mybatis-crypto\n\n\u003ca href=\"https://github.com/WhiteDG/mybatis-crypto/releases\"\u003e\u003cimg alt=\"GitHub release\" src=\"https://img.shields.io/github/release/WhiteDG/mybatis-crypto.svg?style=flat-square\u0026label=latest version\"/\u003e\u003c/a\u003e\n\u003cimg alt=\"GitHub last commit\" src=\"https://img.shields.io/github/last-commit/WhiteDG/mybatis-crypto?style=flat-square\"\u003e\n\u003ca href=\"https://github.com/WhiteDG/mybatis-crypto/actions\"\u003e\u003cimg alt=\"GitHub Workflow Status\" src=\"https://img.shields.io/github/actions/workflow/status/WhiteDG/mybatis-crypto/release.yml?style=flat-square\"\u003e\u003c/a\u003e\n\u003cbr\u003e English | \u003ca href=\"README_CN.MD\"\u003e中文\u003c/a\u003e\n\n## Introduction\n\n`mybatis-crypto` is a field encryption and decryption component based on the MyBatis plugin mechanism. It allows you to\nencrypt and decrypt sensitive data with a simple annotation. It supports custom Encryptor, specifying separate Encryptor\nand key for special fields, and meets most use cases.\n\n## Modules\n\n`mybatis-crypto` consists of three modules:\n\n- `mybatis-crypto-core` The core functionality module of the plugin.\n- `mybatis-crypto-spring-boot-starter` Provides quick integration with `Spring Boot`.\n- `mybatis-crypto-encryptors` Provides several `IEncryptor` implementations.\n\n## Usage\n\n1. Add the dependency\n\n```xml\n\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.github.whitedg\u003c/groupId\u003e\n    \u003cartifactId\u003emybatis-crypto-spring-boot-starter\u003c/artifactId\u003e\n    \u003cversion\u003e${latest.version}\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n2. Implement the IEncryptor\n\n```java\nimport io.github.whitedg.mybatis.crypto.IEncryptor;\n\npublic class MyEncryptor implements IEncryptor {\n\n    @Override\n    public String encrypt(Object val2bEncrypted, String key) throws Exception {\n        // Implement this method to return the encrypted data\n        return \"encrypted string\";\n    }\n\n    @Override\n    public String decrypt(Object val2bDecrypted, String key) throws Exception {\n        // Implement this method to return the decrypted data\n        return \"decrypted string\";\n    }\n}\n```\n\nAlternatively, you can use `mybatis-crypto-encryptors`\n\n```xml\n\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.github.whitedg\u003c/groupId\u003e\n    \u003cartifactId\u003emybatis-crypto-encryptors\u003c/artifactId\u003e\n    \u003cversion\u003e${latest.version}\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nand use the provided `Encryptor` implementations:\n\n- `io.github.whitedg.mybatis.crypto.Base64Encryptor`\n- `io.github.whitedg.mybatis.crypto.BasicTextEncryptor`\n- `io.github.whitedg.mybatis.crypto.AES256Encryptor`\n- `io.github.whitedg.mybatis.crypto.StrongTextEncryptor`\n\n3. Add configurations\n\n```yaml\nmybatis-crypto:\n  # Enable the plugin (default: true)\n  enabled: true\n  # Fail fast during encryption/decryption (default: true)\n  fail-fast: false\n  # Global default Encryptor\n  default-encryptor: io.github.whitedg.mybatis.crypto.BasicTextEncryptor\n  # Default key for Encryptor\n  default-key: global-key\n  # Prefixes of @Param parameters that need to be encrypted\n  mapped-key-prefixes: et,encrypted\n  # Enable encrypted field query (default: false)\n  encrypted-query: true\n  # Entity package path\n  type-packages: io.github.whitedg.**.entity\n  # Keep plaintext parameters\n  keep-parameter: true\n```\n\n4. Specify encrypted fields\n\n- Add the `@EncryptedField` annotation to the fields that need to be encrypted/decrypted\n\n```java\npublic class User {\n    @EncryptedField\n    private String encryptedStr;\n\n    @EncryptedField(encryptor = YourEncryptor.class, key = \"Your Key\")\n    private String customizedStr;\n}\n```\n\n- Use the configured @Param parameter key prefix\n\n```java\nimport org.apache.ibatis.annotations.Param;\n\ninterface YourEntityMapper {\n    int insert(@Param(\"et\") YourEntity entity);\n\n    // Support for List\n    int batchInsert(@Param(\"encrypted-entities\") List\u003cYourEntity\u003e entity);\n\n    // @EncryptedField can be applied to the string parameter\n    // ⚠️If there is only one parameter, @Param is also required\n    int selectByName0(@EncryptedField(encryptor = YourEncryptor.class, key = \"Your Key\") @Param(\"name\") String name);\n\n    // Support for string parameters using @Param key prefix(Uses the global encryptor and key)\n    int selectByName1(@Param(\"encrypted-name\") String name);\n\n    // The result can be an object or a List\n    YourEntity selectOne();\n\n    List\u003cYourEntity\u003e selectList();\n}\n```\n\n## [Demo](https://github.com/WhiteDG/mybatis-crypto/blob/main/mybatis-crypto-demo/README.MD)\n\n## Configuration\n\n| Property                           | Description                                                                                                                                                                                | Default Value |\n|------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------|\n| mybatis-crypto.enabled             | Enable mybatis-crypto                                                                                                                                                                      | true          |\n| mybatis-crypto.fail-fast           | Fail fast during encryption/decryption. true: Throw an exception; false: Use the original value and log a warning level message                                                            | true          |\n| mybatis-crypto.mapped-key-prefixes | Prefixes for @Param parameter names. If a parameter name matches any of the prefixes, encryption/decryption will be applied.                                                               | null          |\n| mybatis-crypto.default-encryptor   | Global default Encryptor class name                                                                                                                                                        | null          |\n| mybatis-crypto.encrypted-query     | Whether to enable exact matching for encrypted field queries                                                                                                                               | false         |\n| mybatis-crypto.type-packages       | Package paths of entity classes. Optional configuration. If configured, the Encryptor will be loaded into the cache during service startup                                                 | null          |\n| mybatis-crypto.keep-parameter      | Whether to keep plaintext parameters of entities. After executing insert/update statements, encrypted fields of entities can choose to keep the plaintext or overwrite with the ciphertext | false         |\n\n## LICENSE\n\n```\nCopyright 2021 WhiteDG\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   https://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhitedg%2Fmybatis-crypto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwhitedg%2Fmybatis-crypto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhitedg%2Fmybatis-crypto/lists"}