Skip to content

gnorium/web-security

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WebSecurity, as used in gnorium.com

A Swift package providing portable security utilities for web applications.

Overview

WebSecurity provides reusable, framework-agnostic security components for authentication, encryption, and authorization. Built on swift-crypto and jwt-kit for cross-platform compatibility.

Components

  • JWTAuthenticator: JWT token signing and verification with configurable claims
  • TOTPAuthenticator: Time-based One-Time Password (RFC 6238) generation and verification
  • PasswordHasher: Salted password hashing with configurable rounds
  • DataEncryptor: AES-GCM encryption/decryption for sensitive data
  • OIDCProvider: OAuth/OIDC authorization URL generation for various providers

Installation

Swift Package Manager

Add WebSecurity to your Package.swift:

dependencies: [
    .package(url: "https://github.com/gnorium/web-security.git", branch: "main")
]

Then add it to your target dependencies:

.target(
    name: "YourTarget",
    dependencies: [
        .product(name: "WebSecurity", package: "web-security")
    ]
)

Requirements

  • Swift 6.2+

Usage

TOTP Authentication

import WebSecurity

let totp = TOTPAuthenticator()
let secret = totp.generateSecret()
let otpauthURL = totp.generateOTPAuthURL(secret: secret, accountName: "user@example.com", issuer: "MyApp")

// Verify a code
let isValid = totp.verifyCode(userCode, secret: secret)

JWT Authentication

import WebSecurity

let jwt = JWTAuthenticator(signers: app.jwt.signers)
let token = try jwt.sign(subject: userID, mfaVerified: true)
let payload = try jwt.verify(token: token)

Password Hashing

import WebSecurity

let hash = PasswordHasher.hash("password123")
let isValid = PasswordHasher.verify("password123", against: hash)

License

Apache License 2.0 - See LICENSE for details

Contributing

Contributions welcome! Please open an issue or submit a pull request.

Related Packages

About

WebSecurity, as used in gnorium.com

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages