Swiftpack.co - TICESoftware/DoubleRatchet as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by TICESoftware.
TICESoftware/DoubleRatchet 2.0.2
Implementation of the Double Ratchet protocol in Swift based on libsodium.
⭐️ 3
🕓 3 years ago
.package(url: "https://github.com/TICESoftware/DoubleRatchet.git", from: "2.0.2")

DoubleRatchet

Implementation of the Double Ratchet protocol in Swift. The cryptographic operations are provided by libsodium entirely.

Installation

SPM

.package(url: "https://github.com/TICESoftware/DoubleRatchet.git", .upToNextMajor(from: "1.0.0"))

In order to build the library it is necessary to link libsodium. The official repository includes scripts to build binaries for specific platforms.

swift build -Xcc -I[header search path] -Xlinker -L[binary path]

When using Xcode you can set the header search path manually to include the libsodium header files and link the static libsodium library.

CodoaPods

pod 'DoubleRatchet'

This uses Sodium as a dependency which includes the pre-compiled libsodium library. No further setup necessary.

Usage

Alice and Bob calculate a shared secret using a secure channel. After that one party can start the conversation as soon as she gets to know the public key of the other one.

import DoubleRatchet

let sharedSecret: Bytes = ...
let info = "DoubleRatchetExample"

let bob = try DoubleRatchet(keyPair: nil, remotePublicKey: nil, sharedSecret: sharedSecret, maxSkip: 20, maxCache: 20, info: info)

// Bob sends his public key to Alice using another channel
// sendToAlice(bob.publicKey)

let alice = try DoubleRatchet(keyPair: nil, remotePublicKey: bob.publicKey, sharedSecret: sharedSecret, maxSkip: 20, maxCache: 20, info: info)

// Now the conversation begins
let message = "Hello, Bob!".bytes
let encryptedMessage = try alice.encrypt(plaintext: message)
let decryptedMessage = try bob.decrypt(message: encryptedMessage)

print(decryptedMessage.utf8String!) // Hello, Bob!

GitHub

link
Stars: 3
Last commit: 2 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics