seckit 1.0.5 copy "seckit: ^1.0.5" to clipboard
seckit: ^1.0.5 copied to clipboard

Secure cryptographic utilities for Dart JWT authentication, field encryption, password hashing, and deterministic hashing.

Seckit #

Secure cryptographic utilities for Dart: JWT authentication, field encryption with HMAC authentication, bcrypt password hashing, and deterministic hashing for searchable fields.

pub package License: MIT

Features #

  • πŸ” JWT Handler - HS256 tokens with expiration validation
  • πŸ”’ Field Encryptor - AES-256-CBC + HMAC authentication (searchable)
  • πŸ›‘οΈ Password Hasher - bcrypt for authentication
  • πŸ” Deterministic Hasher - HMAC-SHA256 for database lookups
  • πŸ“§ Email Utils - Masking and validation

Security Highlights #

βœ… Constant-time comparisons (timing attack prevention)
βœ… HMAC authentication (tampering detection)
βœ… Input validation (DoS prevention)
βœ… No information leakage in errors
βœ… Audited & production-ready

Quick Start #

1. JWT Authentication #

import 'package:seckit/seckit.dart';

final jwt = JwtHandler(
  secretKey: 'your-secret-key-32-characters-long!',
  devAuthToken: 'dev-token',
  isProd: true,
  userIdKey: 'user_id',
);

// Generate token
final token = jwt.generateToken(claims: {'user_id': 123, 'role': 'admin'});

// Validate
final result = jwt.validateToken(token);
if (result.isValue) print('Valid!');

2. Password Hashing (bcrypt - for authentication) #

const hasher = PasswordHasher();

// Registration
final hash = hasher.hash('user-password').asValue!.value;
// Save to DB

// Login
final valid = hasher.verify('user-password', hash).asValue!.value;

3. Field Encryption (AES + HMAC - searchable & reversible) #

final encryptor = FieldEncryptor(
  dbSecretKey: 'base64-encoded-32-byte-key',
  salt: 'unique-salt-16ch',
);

// Encrypt
final encrypted = encryptor.encrypt('user@example.com').asValue!.value;

// Decrypt
final decrypted = encryptor.decrypt(encrypted).asValue!.value;

4. Deterministic Hashing (HMAC - for DB lookups) #

final hasher = DeterministicHasher(
  secretKey: 'secret-key-32-characters-long!',
  salt: 'email-salt-16ch',
);

// Hash for privacy + searchability
final emailHash = hasher.hash('user@example.com').asValue!.value;
// Store emailHash in DB index - same input = same hash

5. Email Masking #

final masked = EmailUtils.mask('john.doe@example.com');
// Returns: "jo***@example.com"

When to Use What? #

Use Case Tool Why
User login/passwords PasswordHasher Non-deterministic (secure)
Search by email/phone DeterministicHasher Same input = same hash
Encrypt SSN/credit card FieldEncryptor Reversible + searchable
API authentication JwtHandler Stateless tokens

Security Requirements #

⚠️ Required in production:

  1. Key Lengths: secretKey β‰₯32 chars, salt β‰₯16 chars
  2. Environment Variables: Never hardcode secrets
final config = Config(
  secretKey: Platform.environment['JWT_SECRET']!,
  dbSecretKey: Platform.environment['DB_SECRET']!,
  devAuthToken: Platform.environment['DEV_TOKEN'] ?? '',
  isProd: Platform.environment['ENV'] == 'production',
);
  1. Rate Limiting: Implement at app level (5 password attempts/min, 100 JWT validations/min)

Documentation #

dart run example/main.dart

License #

MIT License - see LICENSE for details.

1
likes
160
points
5
downloads

Publisher

unverified uploader

Weekly Downloads

Secure cryptographic utilities for Dart JWT authentication, field encryption, password hashing, and deterministic hashing.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

async_lite, bcrypt, crypto, encrypt, jaguar_jwt, path

More

Packages that depend on seckit