Swiftpack.co - proxyco/swift-jwe as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by proxyco.
proxyco/swift-jwe 1.0.1
Swift implementation of JSON Web Encryption (JWE) RFC7516
⭐️ 0
🕓 2 weeks ago
iOS macOS
.package(url: "https://github.com/proxyco/swift-jwe.git", from: "1.0.1")

Swift JWE

Swift JWE is a Swift package that provides a convenient way to encrypt and decrypt data using JSON Web Encryption (JWE) RFC7516.

Supported Key Management Algorithms

The package supports the following key management algorithms:

Supported Content Encryption Algorithms

The package supports the following content encryption algorithms:

  • A128GCM
  • A192GCM
  • A256GCM

Supported Elliptic Curves

The package supports the following elliptic curves:

Usage

To use Swift JWE, follow these simple steps:

  1. Load / Generate the recipient's key pair.
  2. Create a JWE instance with the appropriate protected header.
  3. Use the encrypt method to encrypt the plaintext using the recipient's public key.
  4. Send the compact serialization of the JWE to the recipient.
  5. Use the decrypt method to decrypt the ciphertext using the recipient's private key.

Here's an example:

// Generate recipient key pair
let recipientPrivateKey = Curve25519.KeyAgreement.PrivateKey()
let recipientPublicKey = recipientPrivateKey.publicKey

// Encrypt plaintext using JWE
let plaintext = "Hello, World!".data(using: .utf8)!
var jwe = JWE(
    protectedHeader: .init(
        alg: .ecdhESA256KW,
        enc: .a256GCM,
        zip: .deflate
    )
)
try jwe.encrypt(
    plaintext: plaintext,
    to: recipientPublicKey.jwkRepresentation
)
let compactSerialization = jwe.compactSerialization

// Sender sends JWE compact serialization to recipient...
// ...

// Decrypt ciphertext
let receivedJWE = try JWE(compactSerialization: compactSerialization)
let receivedPlaintext = try receivedJWE.decrypt(
    using: recipientPrivateKey.jwkRepresentation
)

For more information on how to use Swift JWE, please refer to the documentation.

GitHub

link
Stars: 0
Last commit: 2 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Dependencies

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