Coder Social home page Coder Social logo

crypto's Introduction

Crypto

Crypto is an easy-to-use and type safe Swift wrapper for CommonCrypto.

Requirements

  • iOS 8 and later
  • macOS 10.10 and later
  • tvOS 9.0 and later
  • watchOS 2.0 and later
  • Swift 3.2 and later

Installation

Crypto is available via Carthage.

Carthage

To install Crypto using Carthage, add this line to your Cartfile:

github "alexaubry/Crypto"

CocoaPods

Crypto cannot be installed with Carthage yet. Please read #1 for more information.

Usage

Crypto supports the following operations:

Digests

Use the Digest enum to compute the hash of messages.

let message: Data = "secret".data(using: .utf8)!
let hash = Digest.sha256.hash(message: message)

The hash(message:) method returns a Data object containing the hash.

Available digests: .md4, .md5, .sha1, .sha224, .sha256, .sha384, .sha512

HMAC

Use the HMAC enum to compute the HMAC for a given message and key.

let message: Data = "secret".data(using: .utf8)!
let key: Data = ...
let hmac = HMAC.sha256.authenticate(message: message, with: key)

The authenticate(message:,with:) method returns a Data object containing the HMAC code for the message.

Available algorithms: .sha1, .sha224, .sha256, .sha384, .sha512

Key Derivation

Use the KeyDerivation enum to calibrate and derive passwords with the PBKDF2 algorithm.

Key Wrap

Use the SymmetricKeyWrap enum to wrap and unwrap keys with an encryption key.

Encryption and Decryption

Use the Cryptor enum to encrypt and decrypt data.

Random Data

Two random data generators are available:

  • CommonRandom - uses CCRandomGenerateBytes from CommonCrypto
  • SecRandom - uses SecRandomCopyBytes from Security.framework

They both conform to the Random protocol.

Example:

let ccRandom: Data = try CommonRandom.generate(bytes: 32)
let secRandom: Data = try SecRandom.generate(bytes: 32)

This generates 32 bytes of random data.

Author

Written by Alexis Aubry. You can find me on Twitter.

License

Crypto is available under the MIT license. See the LICENSE file for more info.

crypto's People

Contributors

alexisakers avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.