{"id":13354213,"url":"https://github.com/sgl0v/scrypto","last_synced_at":"2025-09-22T23:31:56.683Z","repository":{"id":62453441,"uuid":"55176170","full_name":"sgl0v/SCrypto","owner":"sgl0v","description":"Elegant  Swift interface to access the CommonCrypto routines","archived":false,"fork":false,"pushed_at":"2020-04-07T18:51:33.000Z","size":82,"stargazers_count":38,"open_issues_count":1,"forks_count":14,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-08-28T04:53:31.560Z","etag":null,"topics":["commoncrypto","cryptographic-hash-functions","cryptography","encryption","hmac","ios","swift"],"latest_commit_sha":null,"homepage":null,"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/sgl0v.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}},"created_at":"2016-03-31T19:10:54.000Z","updated_at":"2023-12-22T13:14:15.000Z","dependencies_parsed_at":"2022-11-02T00:00:50.547Z","dependency_job_id":null,"html_url":"https://github.com/sgl0v/SCrypto","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/sgl0v/SCrypto","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgl0v%2FSCrypto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgl0v%2FSCrypto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgl0v%2FSCrypto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgl0v%2FSCrypto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sgl0v","download_url":"https://codeload.github.com/sgl0v/SCrypto/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgl0v%2FSCrypto/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276489797,"owners_count":25651610,"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","status":"online","status_checked_at":"2025-09-22T02:00:08.972Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["commoncrypto","cryptographic-hash-functions","cryptography","encryption","hmac","ios","swift"],"created_at":"2024-07-29T21:01:57.098Z","updated_at":"2025-09-22T23:31:53.451Z","avatar_url":"https://github.com/sgl0v.png","language":"Swift","funding_links":[],"categories":["Libs","Security [🔝](#readme)"],"sub_categories":["Security"],"readme":"# \u003cp align=\"center\"\u003eSCrypto\u003c/p\u003e\n\n[![Build Status](https://travis-ci.org/sgl0v/SCrypto.svg?branch=master)](https://travis-ci.org/sgl0v/SCrypto)\n[![codecov.io](https://codecov.io/github/sgl0v/SCrypto/coverage.svg?branch=master)](https://codecov.io/github/sgl0v/SCrypto?branch=master)\n[![Version](https://img.shields.io/cocoapods/v/SCrypto.svg?style=flat)](http://cocoadocs.org/docsets/SCrypto)\n[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![License](https://img.shields.io/cocoapods/l/SCrypto.svg?style=flat)](http://cocoadocs.org/docsets/SCrypto)\n\n[[Overview](#overview) \u0026bull; [Requirements](#requirements) \u0026bull; [Installation](#installation) \u0026bull; [Usage](#usage) \u0026bull; [Alternatives](#alternatives) \u0026bull; [Licence](#licence)]\n\n---\n\n## Overview\nSCrypto provides neat Swift interface to access the CommonCrypto routines.\n### Features\n\n- [x] Essential `Data` and `String` extensions for message digest, HMAC, PBKDF, symmetric encryption calculation\n- [x] Swift 5.1 support\n- [x] Cocoapods, Carthage and Swift Package Manager compatible\n- [x] Comprehensive Unit Test Coverage\n- [x] [Complete Documentation](http://cocoadocs.org/docsets/SCrypto)\n- [x] iOS and OS X support\n\n---\n\n## Requirements\n\n- iOS 9.0+ / macOS 10.11+\n- Swift 3.0+\n- Xcode 8.0+\n\n---\n\n## Installation\n### Cocoapods\n\n[CocoaPods](http://cocoapods.org) is a dependency manager for Cocoa projects. You can install it with the following command:\n\n```bash\n$ gem install cocoapods\n```\n\nTo integrate SCrypto into your Xcode project using CocoaPods, specify it in your `Podfile`:\n\n```ruby\nsource 'https://github.com/CocoaPods/Specs.git'\nplatform :ios, '9.0'\nuse_frameworks!\n\npod 'SCrypto', '~\u003e 2.0.0'\n```\n\nThen, run the following command:\n\n```bash\n$ pod install\n```\n\n### Carthage\n[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. You can install Carthage with [Homebrew](http://brew.sh/) using the following command:\n\n```bash\n$ brew update\n$ brew install carthage\n```\n\nTo integrate SCrypto into your Xcode project using Carthage, specify it in your `Cartfile`:\n\n```ogdl\ngithub \"sgl0v/SCrypto\" ~\u003e 1.0.0\n```\n\nRun `carthage update` to build the framework and drag the built `SCrypto.framework` into your Xcode project.\n\n### Swift Package Manager\n\nYou can add the SCrypto framework to your project via Swift Package Manager. Add the following line to the dependencies in your `Package.swift` file:\n\n```swift\n.package(url: \"https://github.com/sgl0v/SCrypto\", exact: \"\u003clatest version\u003e\"),\n```\n\nFinally, include \"SCrypto\" as a dependency for your executable target:\n\n```\n.target(name: \"\u003ctarget name\u003e\", dependencies: [\"SCrypto\"])\n```\n\n### Manually\nIf you prefer not to use either of the mentioned dependency managers, you can integrate SCrypto into your project manually.\n\n- Open up Terminal, `cd` into your top-level project directory, and run the following command \"if\" your project is not initialized as a git repository:\n\n```bash\n$ git init\n```\n\n- Add SCrypto as a git [submodule](http://git-scm.com/docs/git-submodule) by running the following command:\n\n```bash\n$ git submodule add https://github.com/sgl0v/SCrypto.git\n```\n\n- Open the new `SCrypto` folder, and drag the `SCrypto.xcodeproj` into the Project Navigator of your application's Xcode project.\n\n    \u003e The `SCrypto.xcodeproj` should appear nested underneath your application's blue project icon. Whether it is above or below all the other Xcode groups does not matter.\n\n- Select the `SCrypto.xcodeproj` in the Project Navigator and verify the deployment target matches that of your application target.\n- Next, select your application project in the Project Navigator (blue project icon) to navigate to the target configuration window and select the application target under the \"Targets\" heading in the sidebar.\n- In the tab bar at the top of that window, open the \"General\" panel.\n- Click on the `+` button under the \"Embedded Binaries\" section.\n- You will see two different `SCrypto.xcodeproj` folders each with two different versions of the `SCrypto.framework iOS` nested inside a `Products` folder.\n\n    \u003e It doesn't matter which `Products` folder you choose from.\n\n- Just select the `SCrypto.framework iOS` and that's it!\n\n\t\u003e The `SCrypto.framework` is automagically added as a target dependency and should appear as a linked and embedded framework in the `Build Phases` section.\n\n---\n\n## Usage\n### Message Digest ([MD5](https://en.wikipedia.org/wiki/MD5), [SHA](https://en.wikipedia.org/wiki/Secure_Hash_Algorithm))\nMessage digests are secure one-way [cryptographic hash functions](https://en.wikipedia.org/wiki/Cryptographic_hash_function) that take arbitrary-sized data and output a fixed-length hash value.\n\n```swift\nlet sha256 = \"message\".SHA256()\n```\n\n### Keyed-hash message authentication code ([HMAC](https://en.wikipedia.org/wiki/Hash-based_message_authentication_code))\nHash-based message authentication codes (or HMACs) provides a way for calculating message authentication codes using a cryptographic hash function coupled with a secret key. You can use an HMAC to verify both the integrity and authenticity of a message. The following standard hash algorithm are supported: SHA1, MD5, SHA256, SHA384, SHA512, SHA224.\n\n```swift\nlet secretKey = try! Data.random(32)\nlet message = \"message\".data(using: String.Encoding.utf8)!\nlet hmac = message.hmac(.SHA256, key: secretKey)\n```\n\n### Pseudorandom number generator ([PRNG](https://en.wikipedia.org/wiki/Pseudorandom_number_generator))\nGenerates cryptographically strong random bits suitable for use as cryptographic keys, IVs, nonces etc.\n\n```swift\nlet randomBytes = try! Data.random(16)\n```\n\n### Symmetric-key algorithms ([AES](https://en.wikipedia.org/wiki/Advanced_Encryption_Standard), [DES](https://en.wikipedia.org/wiki/Data_Encryption_Standard), [TripleDES](https://en.wikipedia.org/wiki/Triple_DES), [CAST](https://en.wikipedia.org/wiki/CAST5), [RC2](https://en.wikipedia.org/wiki/RC2), [RC4](https://en.wikipedia.org/wiki/RC4), [Blowfish](https://en.wikipedia.org/wiki/Blowfish_(cipher)))\n\nSymmetric-key algorithms use the same cryptographic keys for both encryption of plaintext and decryption of ciphertext. Note that symmetric encryption only provides secrecy but not integrity. There are recent encryption modes which combine symmetric encryption and checked integrity (not supported by CommonCrypto). For this reason it is strongly recommended to combine encryption with a HMAC.\n\nHere is the way to encrypt and decrypt data via AES algorithm in CBC mode with PKCS7 Padding:\n\n```swift\nlet plaintext = \"plain text\".data(using: String.Encoding.utf8)!\nlet sharedSecretKey = \"shared_secret_key\".data(using: String.Encoding.utf8)!.SHA256() // AES-256\nlet IV = try! Data.random(16) // Randomly generated IV. Length is equal to the AES block size(128)\nlet ciphertext = try! plaintext.encrypt(.AES, options: .PKCS7Padding, key: sharedSecretKey, iv: IV)\nlet plaintext2 = try! ciphertext.decrypt(.AES, options: .PKCS7Padding, key: sharedSecretKey, iv: IV)\n```\n\n### Password-Based Key Derivation Function ([PBKDF2](https://en.wikipedia.org/wiki/PBKDF2))\nKey derivation functions are used for turning a passphrase into an arbitrary length key for use as a cryptographic key in subsequent operations.\n\n```swift\nlet password = \"password\".data(using: String.Encoding.utf8)!\nlet salt = try! Data.random(32)\nlet derivedKey = try! password.derivedKey(salt, pseudoRandomAlgorithm: .SHA256, rounds: 20, derivedKeyLength: 32)\n```\n\n---\n\n## Alternatives\nLooking for something else? Try another Swift CommonCrypto wrappers:\n\n- [RNCryptor](https://github.com/RNCryptor/RNCryptor)\n- [IDZSwiftCommonCrypto](https://github.com/iosdevzone/IDZSwiftCommonCrypto)\n- [Crypto](https://github.com/soffes/Crypto)\n\n---\n\n## Licence\n\n`SCrypto` is MIT-licensed. See `LICENSE`.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsgl0v%2Fscrypto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsgl0v%2Fscrypto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsgl0v%2Fscrypto/lists"}