{"id":1016,"url":"https://github.com/vpeschenkov/SecureDefaults","last_synced_at":"2025-08-06T13:32:17.594Z","repository":{"id":34461455,"uuid":"179337733","full_name":"vpeschenkov/SecureDefaults","owner":"vpeschenkov","description":" Elevate the security of your UserDefaults with this lightweight wrapper that adds a layer of AES-256 encryption","archived":false,"fork":false,"pushed_at":"2024-05-06T13:37:24.000Z","size":611,"stargazers_count":227,"open_issues_count":5,"forks_count":17,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-11-24T08:04:17.366Z","etag":null,"topics":["aes","aes-256","aes-encryption","ios","macos","swift","swift5","userdefaults"],"latest_commit_sha":null,"homepage":"","language":"Swift","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/vpeschenkov.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2019-04-03T17:26:16.000Z","updated_at":"2024-08-21T08:03:15.000Z","dependencies_parsed_at":"2024-06-19T17:12:01.806Z","dependency_job_id":"c610c325-dcc5-4603-aee7-f9248b2e5a6f","html_url":"https://github.com/vpeschenkov/SecureDefaults","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vpeschenkov%2FSecureDefaults","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vpeschenkov%2FSecureDefaults/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vpeschenkov%2FSecureDefaults/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vpeschenkov%2FSecureDefaults/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vpeschenkov","download_url":"https://codeload.github.com/vpeschenkov/SecureDefaults/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228905459,"owners_count":17989771,"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","aes-256","aes-encryption","ios","macos","swift","swift5","userdefaults"],"created_at":"2024-01-05T20:15:37.109Z","updated_at":"2024-12-09T14:30:50.274Z","avatar_url":"https://github.com/vpeschenkov.png","language":"Swift","readme":"# SecureDefaults for iOS, macOS\n\n![](.resources/header.png)\n\n[![Build Status](https://travis-ci.com/vpeschenkov/SecureDefaults.svg?token=HrZYyqqJZx2172zxUQSb\u0026branch=master\u0026style=flat)](https://travis-ci.com/vpeschenkov/SecureDefaults)\n[![Platform](https://img.shields.io/cocoapods/p/SecureDefaults.svg?style=flat)](https://cocoapods.org/pods/SecureDefaults)\n[![Version](https://img.shields.io/cocoapods/v/SecureDefaults.svg?style=flat)](https://cocoapods.org/pods/SecureDefaults)\n[![Carthage compatible](https://img.shields.io/badge/carthage-compatible-blue.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![Swift Package Manager compatible](https://img.shields.io/badge/swift%20package%20manager-compatible-brightgreen.svg?style=flat)](https://github.com/apple/swift-package-manager)\n[![License](https://img.shields.io/cocoapods/l/SecureDefaults.svg?style=flat)](https://cocoapods.org/pods/SecureDefaults)\n\n`SecureDefaults` is a wrapper over `UserDefaults/NSUserDefaults` with an extra [AES-256](https://en.wikipedia.org/wiki/Advanced_Encryption_Standard) encryption layer (key size has **256-bit** length). It encludes:\n- AES-256 encryption\n- Password stretching with PBKDF2\n- Encrypt-then-hash HMAC\n- Password salting\n- Random IV\n\n\u003e The design and strength of all key lengths of the AES algorithm (i.e., 128, 192 and 256) are sufficient to protect classified information up to the SECRET level. TOP SECRET information will require use of either the 192 or 256 key lengths. The implementation of AES in products intended to protect national security systems and/or information must be reviewed and certified by NSA prior to their acquisition and use. \u003csup\u003e[\\[1\\]](https://csrc.nist.gov/projects/cryptographic-standards-and-guidelines/archived-crypto-projects/aes-development)\u003c/sup\u003e\n\n# Table of Contents\n- [Requirements](#requirements)\n- [Usage](#usage)\n- [Installation](#installation)\n- [Acknowledgments](#acknowledgments)\n- [Contributing](#contributing)\n- [Author](#author)\n- [License](#license)\n\n## Requirements\n\n- iOS 12+\n- Swift 5+\n\n## Usage\n\nIt is pretty simple to use `SecureDefaults` instead of `UserDefaults/NSUserDefaults`. In most cases, it is the same thing that is `UserDefaults`. You just need to set a password to make it work.\n\nReplace the following code:\n\n```swift\nUserDefaults.standard\n```\n\nby this one:\n\n```swift\nlet defaults = SecureDefaults.shared\n// Ensures that a password has not already been set. \n// Setting a password multiple times will cause the key to be regenerated, \n// resulting in the loss of any previously encrypted data.\nif !defaults.isKeyCreated {\n    defaults.password = NSUUID().uuidString // Or any password you wish\n}\n```\n\nTo use the app and keychain groups:\n\n```swift\nlet defaults = SecureDefaults(suiteName: \"app.group\") // Sets a shared app group\ndefaults.keychainAccessGroup = \"keychain.group\" // Sets a shrared keychain group \nif !defaults.isKeyCreated {\n    defaults.password = NSUUID().uuidString // Or any password you wish\n}\n```\n\n`SecureDefaults` is not able to catch that any particular data is encrypted, to obtain a raw value, use the following method:\n\n```swift\npublic func rawObject(forKey defaultName: String) -\u003e Any?\n```\n\n## Installation\n\n### [CocoaPods](https://cocoapods.org)\n\n`SecureDefaults` is available through [CocoaPods](https://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod 'SecureDefaults', '1.2.2' # Swift 5.0\n```\n\n### [Carthage](https://github.com/Carthage/Carthage)\n\nAdd this to `Cartfile`\n\n```ruby\ngithub \"vpeschenkov/SecureDefaults\" == 1.2.2\n```\n\n```sh\n$ carthage update\n```\n\n### [Swift Package Manager](https://github.com/apple/swift-package-manager)\n\nCreate a `Package.swift` file.\n\n```swift\n\nimport PackageDescription\n\nlet package = Package(\n  name: \"YourProject\",\n  dependencies: [\n    .package(url: \"https://github.com/vpeschenkov/SecureDefaults\", \"1.2.2\")\n  ],\n  targets: [\n    .target(name: \"YourProject\", dependencies: [\"SecureDefaults\"])\n  ]\n)\n```\n\n```sh\n$ swift build\n```\n\n## Contributing\n\n- If you **need help** or you'd like to **ask a general question**, open an issue.\n- If you **found a bug**, open an issue.\n- If you **have a feature request**, open an issue.\n- If you **want to contribute**, submit a pull request.\n\n## Acknowledgments\n\nA big thanks to the following individuals:\n\n- [Rob Napier](https://github.com/rnapier) - for this awesome article [\"Properly Encrypting With AES With CommonCrypto\"](http://robnapier.net/aes-commoncrypto)\n- [Håvard Fossli](https://github.com/hfossli) - for this awesome Gist [\"AES 256 in swift 4 with CommonCrypto\"](https://gist.github.com/hfossli/7165dc023a10046e2322b0ce74c596f8)\n\n## Author\n\nVictor Peschenkov, v.peschenkov@gmail.com\n\n## License\n\n`SecureDefaults` is available under the MIT license. See the [LICENSE](LICENSE) file for more info.\n","funding_links":[],"categories":["Database","Libs","Data Management [🔝](#readme)"],"sub_categories":["Getting Started","Data Management","Linter"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvpeschenkov%2FSecureDefaults","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvpeschenkov%2FSecureDefaults","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvpeschenkov%2FSecureDefaults/lists"}