{"id":15066910,"url":"https://github.com/lemo-nade-room/swift-crypto-codable","last_synced_at":"2026-01-02T20:34:48.072Z","repository":{"id":255895892,"uuid":"853835797","full_name":"lemo-nade-room/swift-crypto-codable","owner":"lemo-nade-room","description":"Codableな型の特定のプロパティをEncode時にAES暗号化する","archived":false,"fork":false,"pushed_at":"2025-02-06T00:58:33.000Z","size":42,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-15T03:42:09.509Z","etag":null,"topics":["aes","codable","crypto","event-sourcing","swift"],"latest_commit_sha":null,"homepage":"https://lemo-nade-room.github.io/swift-crypto-codable/documentation/cryptocodable/","language":"Swift","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/lemo-nade-room.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":"2024-09-07T17:07:18.000Z","updated_at":"2025-02-06T00:58:36.000Z","dependencies_parsed_at":"2024-09-07T20:50:59.781Z","dependency_job_id":null,"html_url":"https://github.com/lemo-nade-room/swift-crypto-codable","commit_stats":null,"previous_names":["lemo-nade-room/swift-crypto-codable"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lemo-nade-room%2Fswift-crypto-codable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lemo-nade-room%2Fswift-crypto-codable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lemo-nade-room%2Fswift-crypto-codable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lemo-nade-room%2Fswift-crypto-codable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lemo-nade-room","download_url":"https://codeload.github.com/lemo-nade-room/swift-crypto-codable/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243822311,"owners_count":20353496,"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","codable","crypto","event-sourcing","swift"],"created_at":"2024-09-25T01:13:53.847Z","updated_at":"2026-01-02T20:34:48.021Z","avatar_url":"https://github.com/lemo-nade-room.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CryptoCodable\n\n`CryptoCodable`は、Appleの`swift-crypto`を使用してJSONエンコード時にAES-GCMでプロパティを暗号化するためのSwiftライブラリです。このライブラリは、`Sendable`対応であると同時に、`Codable`、`Hashable`にも準拠したプロパティを保護し、復号もシンプルに行えるように設計されています。\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://lemo-nade-room.github.io/swift-crypto-codable/documentation/cryptocodable\"\u003e\n        \u003cimg src=\"https://design.vapor.codes/images/readthedocs.svg\" alt=\"Documentation\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"LICENSE\"\u003e\n        \u003cimg src=\"https://design.vapor.codes/images/mitlicense.svg\" alt=\"MIT License\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/lemo-nade-room/swift-crypto-codable/actions/workflows/ci.yaml\"\u003e\n        \u003cimg src=\"https://github.com/lemo-nade-room/swift-crypto-codable/actions/workflows/ci.yaml/badge.svg\" alt=\"Testing Status\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://swift.org\"\u003e\n        \u003cimg src=\"https://design.vapor.codes/images/swift60up.svg\" alt=\"Swift 6.0+\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n## サポート\n\n- macOS \u003e= 13\n- Swift \u003e= 6.0\n\n## 特徴\n- AES-GCMでJSONプロパティを暗号化・復号\n- 暗号化対象のプロパティは`Sendable`、`CryptoFieldable`に準拠している必要がある\n\n## インストール\n\nこのライブラリはSwift Package Managerを使用してインストールできます。\n\n```swift\nlet package = Package(\n    ...\n    dependencies: [\n        ...\n        .package(url: \"https://github.com/lemo-nade-room/swift-crypto-codable.git\", branch: \"main\"),\n    ],\n    targets: [\n        .target(\n            name: \"YourApp\",\n            dependencies: [\n                .product(name: \"CryptoCodable\", package: \"swift-crypto-codable\"),\n            ]\n        ),\n        ...\n    ]\n    ...\n)\n```\n\n## ドキュメンテーション\n\n[DocCによるAPIドキュメント](https://lemo-nade-room.github.io/swift-crypto-codable/documentation/cryptocodable)があります\n\n## 使用方法\n\n### 1. CryptoFieldプロパティラッパーを使った型を定義\n\nまず、暗号化対象のプロパティを持つ`Codable`な型を定義します。\n\n```swift\nimport CryptoCodable\nimport Foundation\n\nstruct Event: Hashable, Codable, Sendable {\n    var id: UUID\n    var 職業: String\n    @CryptoField var 氏名: String\n    @CryptoField var LINEやってる: Bool\n    @CryptoField var 誕生日: Date\n    @CryptoField var 年齢: Int\n    @CryptoField var 身長: Double\n    @CryptoField var 体重: Double?\n}\n```\n\n### 2. 暗号化\n\n次に、暗号鍵を設定して暗号化を行います。暗号鍵が設定されていない場合、`fatalError`が発生します。\n\n```swift\nimport CryptoCodable\nimport Foundation\n\nlet jsonData: Data = try CryptoConfigContainer.$key.withValue(.init(size: .bits256)) {\n    try JSONEncoder().encode(event)\n}\n```\n\n### 3. 復号\n\n暗号化されたデータを復号します。復号時にも暗号鍵を設定します。\n\n```swift\nimport CryptoCodable\nimport Foundation\n\nlet event: Event = try CryptoConfigContainer.$key.withValue(key) {\n    try JSONDecoder().decode(Event.self, from: encrypted)\n}\n```\n\n## 暗号化可能なプロパティの条件\n- プロパティの型は`Sendable`と`CryptoFieldable`に準拠している必要があります。\n- Int, String, Double, Bool, Date, Optional型はデフォルトで準拠している\n\n## 暗号鍵が設定されていない場合\n暗号鍵が設定されていない場合、プロパティには`nil`が設定されますが、デコード自体は成功します。\n\n- 暗号鍵が異なる場合には、`DecryptFailure`エラーが発生します。\n\n## ライセンス\nこのライブラリはMITライセンスで提供されています。詳細は[LICENSE](./LICENSE)ファイルをご覧ください。\n\nなお、このプロジェクトは`apple/swift-crypto`に依存しています。`apple/swift-crypto`はApache 2.0ライセンスに基づいて提供されています。詳しくは[こちら](https://raw.githubusercontent.com/apple/swift-crypto/main/LICENSE.txt)をご確認ください。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flemo-nade-room%2Fswift-crypto-codable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flemo-nade-room%2Fswift-crypto-codable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flemo-nade-room%2Fswift-crypto-codable/lists"}