All Projects → sgl0v → SCrypto

sgl0v / SCrypto

Licence: MIT license
Elegant Swift interface to access the CommonCrypto routines

Programming Languages

swift
15916 projects
shell
77523 projects
ruby
36898 projects - #4 most used programming language
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to SCrypto

Cryptoswift
CryptoSwift is a growing collection of standard and secure cryptographic algorithms implemented in Swift
Stars: ✭ 8,846 (+22582.05%)
Mutual labels:  hmac, commoncrypto
instacop
InstaCop — Enhanced shopping experience for the adidas.com online store 🦓
Stars: ✭ 68 (+74.36%)
Mutual labels:  hmac
aescryptable
AES encryption/decryption with random iv. Swift 5 and up.
Stars: ✭ 29 (-25.64%)
Mutual labels:  commoncrypto
lazysodium-java
A Java implementation of the Libsodium crypto library. For the lazy dev.
Stars: ✭ 110 (+182.05%)
Mutual labels:  hmac
signature
HMAC and RSA signature for Laravel and Lumen
Stars: ✭ 26 (-33.33%)
Mutual labels:  hmac
hkdf
A standalone Java 7 implementation of HMAC-based key derivation function (HKDF) defined in RFC 5869 first described by Hugo Krawczyk. HKDF follows the "extract-then-expand" paradigm which is compatible to NIST 800-56C Rev. 1 two step KDF
Stars: ✭ 47 (+20.51%)
Mutual labels:  hmac
Jwt
JSON Web Token library
Stars: ✭ 242 (+520.51%)
Mutual labels:  hmac
hmac sha256
Minimal HMAC-SHA256 implementation in C / C++
Stars: ✭ 35 (-10.26%)
Mutual labels:  hmac
hmac.nim
HMAC-SHA1 and HMAC-MD5 hashing in Nim
Stars: ✭ 13 (-66.67%)
Mutual labels:  hmac
noble-hashes
Audited & minimal JS implementation of SHA2, SHA3, RIPEMD, BLAKE2/3, HMAC, HKDF, PBKDF2 & Scrypt
Stars: ✭ 213 (+446.15%)
Mutual labels:  hmac
micro-service-practice
OpenStack+Docker+RestAPI+OAuth/HMAC+RabbitMQ/ZMQ+OpenResty/HAProxy/Nginx/APIGateway+Bootstrap/AngularJS+Ansible+K8S/Mesos/Marathon构建/探索微服务最佳实践。
Stars: ✭ 25 (-35.9%)
Mutual labels:  hmac
crypto
🔐 Fastest crypto library for Deno written in pure Typescript. AES, Blowfish, CAST5, DES, 3DES, HMAC, HKDF, PBKDF2
Stars: ✭ 40 (+2.56%)
Mutual labels:  hmac
webcrypto
A WebCrypto Polyfill for NodeJS
Stars: ✭ 111 (+184.62%)
Mutual labels:  hmac
requests-http-signature
A Requests auth module for the IETF HTTP Message Signatures draft standard
Stars: ✭ 63 (+61.54%)
Mutual labels:  hmac
id-mask
IDMask is a Java library for masking internal ids (e.g. from your DB) when they need to be published to hide their actual value and to prevent forging. It has support optional randomisation has a wide support for various Java types including long, UUID and BigInteger. This library bases its security on strong cryptographic primitives.
Stars: ✭ 39 (+0%)
Mutual labels:  hmac
pbkdf2-hmac-sha256
sha256, hmac with sha256 and pbkdf2 with hmac-sha256 in one header file
Stars: ✭ 19 (-51.28%)
Mutual labels:  hmac
SpinalCrypto
SpinalHDL - Cryptography libraries
Stars: ✭ 36 (-7.69%)
Mutual labels:  hmac
rust-hmac-sha256
A small, self-contained SHA256 and HMAC-SHA256 implementation.
Stars: ✭ 24 (-38.46%)
Mutual labels:  hmac
cryptosuite2
Cryptographic suite for Arduino (SHA, HMAC-SHA)
Stars: ✭ 23 (-41.03%)
Mutual labels:  hmac
hash-wasm
Lightning fast hash functions using hand-tuned WebAssembly binaries
Stars: ✭ 382 (+879.49%)
Mutual labels:  hmac

SCrypto

Build Status codecov.io Version Carthage Compatible License

[OverviewRequirementsInstallationUsageAlternativesLicence]


Overview

SCrypto provides neat Swift interface to access the CommonCrypto routines.

Features

  • Essential Data and String extensions for message digest, HMAC, PBKDF, symmetric encryption calculation
  • Swift 5.1 support
  • Cocoapods, Carthage and Swift Package Manager compatible
  • Comprehensive Unit Test Coverage
  • Complete Documentation
  • iOS and OS X support

Requirements

  • iOS 9.0+ / macOS 10.11+
  • Swift 3.0+
  • Xcode 8.0+

Installation

Cocoapods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate SCrypto into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!

pod 'SCrypto', '~> 2.0.0'

Then, run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate SCrypto into your Xcode project using Carthage, specify it in your Cartfile:

github "sgl0v/SCrypto" ~> 1.0.0

Run carthage update to build the framework and drag the built SCrypto.framework into your Xcode project.

Swift Package Manager

You can add the SCrypto framework to your project via Swift Package Manager. Add the following line to the dependencies in your Package.swift file:

.package(url: "https://github.com/sgl0v/SCrypto", exact: "<latest version>"),

Finally, include "SCrypto" as a dependency for your executable target:

.target(name: "<target name>", dependencies: ["SCrypto"])

Manually

If you prefer not to use either of the mentioned dependency managers, you can integrate SCrypto into your project manually.

  • 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:
$ git init
  • Add SCrypto as a git submodule by running the following command:
$ git submodule add https://github.com/sgl0v/SCrypto.git
  • Open the new SCrypto folder, and drag the SCrypto.xcodeproj into the Project Navigator of your application's Xcode project.

    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.

  • Select the SCrypto.xcodeproj in the Project Navigator and verify the deployment target matches that of your application target.

  • 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.

  • In the tab bar at the top of that window, open the "General" panel.

  • Click on the + button under the "Embedded Binaries" section.

  • You will see two different SCrypto.xcodeproj folders each with two different versions of the SCrypto.framework iOS nested inside a Products folder.

    It doesn't matter which Products folder you choose from.

  • Just select the SCrypto.framework iOS and that's it!

    The SCrypto.framework is automagically added as a target dependency and should appear as a linked and embedded framework in the Build Phases section.


Usage

Message Digest (MD5, SHA)

Message digests are secure one-way cryptographic hash functions that take arbitrary-sized data and output a fixed-length hash value.

let sha256 = "message".SHA256()

Keyed-hash message authentication code (HMAC)

Hash-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.

let secretKey = try! Data.random(32)
let message = "message".data(using: String.Encoding.utf8)!
let hmac = message.hmac(.SHA256, key: secretKey)

Pseudorandom number generator (PRNG)

Generates cryptographically strong random bits suitable for use as cryptographic keys, IVs, nonces etc.

let randomBytes = try! Data.random(16)

Symmetric-key algorithms (AES, DES, TripleDES, CAST, RC2, RC4, Blowfish)

Symmetric-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.

Here is the way to encrypt and decrypt data via AES algorithm in CBC mode with PKCS7 Padding:

let plaintext = "plain text".data(using: String.Encoding.utf8)!
let sharedSecretKey = "shared_secret_key".data(using: String.Encoding.utf8)!.SHA256() // AES-256
let IV = try! Data.random(16) // Randomly generated IV. Length is equal to the AES block size(128)
let ciphertext = try! plaintext.encrypt(.AES, options: .PKCS7Padding, key: sharedSecretKey, iv: IV)
let plaintext2 = try! ciphertext.decrypt(.AES, options: .PKCS7Padding, key: sharedSecretKey, iv: IV)

Password-Based Key Derivation Function (PBKDF2)

Key derivation functions are used for turning a passphrase into an arbitrary length key for use as a cryptographic key in subsequent operations.

let password = "password".data(using: String.Encoding.utf8)!
let salt = try! Data.random(32)
let derivedKey = try! password.derivedKey(salt, pseudoRandomAlgorithm: .SHA256, rounds: 20, derivedKeyLength: 32)

Alternatives

Looking for something else? Try another Swift CommonCrypto wrappers:


Licence

SCrypto is MIT-licensed. See LICENSE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].