Swift JWE is a Swift package that provides a convenient way to encrypt and decrypt data using JSON Web Encryption (JWE) RFC7516.
The package supports the following key management algorithms:
The package supports the following content encryption algorithms:
The package supports the following elliptic curves:
secp256k1RFC8812 Section 3.1
To use Swift JWE, follow these simple steps:
JWEinstance with the appropriate protected header.
encryptmethod to encrypt the plaintext using the recipient's public key.
decryptmethod 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.
|Last commit: 2 weeks ago|
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics