Bitwark β

Provides robust security for Rust applications through compact binary tokens and automated cryptographic defenses.
π Introduction
Bitwark is your go-to library for enhancing security in Rust applications. It offers a streamlined, bandwidth-friendly version of JSON Web Tokens (JWTs) and includes features like automatic key rotation and data salting to bolster your app's defenses.
π Key Features:
- Compact Tokens: Uses binary format for signed payloads, saving space compared to traditional JWTs.
- Advanced Encryption: Employs EdDSA with Blake3 for robust signing and verification out of the box.
- Dynamic Key Rotation: Simplifies the process to update keys and salts, keeping your security measures up-to-date.
- Enhanced Security with Salting: Adds random data to payloads, making it tougher for attackers to crack.
- Performance Optimized: Designed to be lightweight, ensuring your applications run smoothly under pressure.
π οΈ Getting Started
Explore the secure features of Bitwark for your Rust applications:
All-in-One Example (Alternative to JWT)
Imagine you have a structure you wish to sign and send back to the user:
First, generate a key that expires after 10 minutes, though you can set it for days, months, or years as needed. For a non-expiring key, simply use EdDsaKey::generate()
:
let exp_key = generate.unwrap;
Next, create the token. SaltyExpiringSigned
adds a default 64-byte salt and includes an expiration time:
let token_object = Token ;
let token = new.unwrap;
Finally, prepare the token for the client. You can return it as bytes or convert it to base64:
let token_bytes: = token.encode_and_sign.unwrap;
When the user provides this token to your service, verifying it is straightforward:
let token = decode_and_verify.unwrap;
if token.permissions.contains
More Comprehensive Examples Follow
Signed Payload decoded as binary (alternative to JWT)
use ;
use ;
use Duration;
// Generate an EdDSA key pair and salt with a validity period
let exp_key = generate.unwrap;
let exp_salt = generate.unwrap;
// Instantiate a token with specified claims.
let claims = Claims ;
let token = new.unwrap;
// Create a binary encoding of the token, signed with key and salt.
let signed_token_bytes = token.encode_and_sign_salted.expect;
// Decode the token and verify its signature and validity.
let decoded_token = decode_and_verify_salted.expect;
assert_eq!;
Key Rotation
use ;
use Duration;
// creating a key
let key = generate?;
// Rotating key
let mut expiring_key = new;
if expiring_key.has_expired
// Creating a payload
let payload = new;
// Encode the payload with signature based on the expiring key
let signed_payload_bytes = payload.encode_and_sign?;
// Decode the signed payload with verifying signature with payload's integrity
let decoded_payload = decode_and_verify?;
assert_eq!;
Salt Example
use ;
use SignedPayload;
use Duration;
// Make a new salt.
let salt = generate.unwrap;
// Make a salt that lasts for 10 seconds.
let mut expiring_salt = new.unwrap;
// Change the salt if it's too old.
if expiring_salt.has_expired
// Make a key that lasts for 120 seconds.
let key = generate.unwrap;
// Make a payload for signing
let payload = new;
// Combine message and signature into one piece.
let signature_bytes = payload.encode_and_sign_salted.expect;
// Separate message and signature, verifying validity.
let decoded_result =
decode_and_verify_salted;
assert!;
π‘ Motivation
In today's digital landscape, security must not come at the expense of performance. Bitwark addresses this challenge by:
- Providing lightweight, bandwidth-efficient tokens for data exchange.
- Offering robust security features like automatic key rotation and salting to adapt to evolving threats.
π± Contribution
Be a Part of Bitwarkβs Journey!
We believe in the power of community, and Bitwark thrives on contributions from developers like you:
- Propose Ideas: Found a bug or have an idea? Open an Issue!
- Code Contributions: Enhance Bitwark by submitting Pull Requests with your code.
- Documentation: Help us keep our documentation clear and helpful.
- Engage: Participate in community discussions to shape Bitwark's future.
π License
Bitwark is licensed under the MIT License or Apache-2.0 to ensure it remains accessible for all developers.