Skip to main content

Crypto

The Crypto module provides comprehensive cryptographic capabilities for Soul, including hashing, HMAC authentication, Base64 encoding, and JWT (JSON Web Token) operations. It offers essential security functions for data integrity, authentication, and secure communication.

Base64 Encoding

base64Encode - Encode string to Base64

Convert a string to Base64 encoding:

base64Decode - Decode Base64 to string

Convert Base64 encoded string back to original text:

base64UrlEncode - URL-safe Base64 encoding

Encode string using URL-safe Base64 format (no padding):

base64UrlDecode - URL-safe Base64 decoding

Decode URL-safe Base64 encoded strings:

Hash Functions

md5 - Compute MD5 hash

Generate MD5 hash of a string (hex format):

sha256 - Compute SHA-256 hash

Generate SHA-256 hash of a string (hex format):

sha512 - Compute SHA-512 hash

Generate SHA-512 hash of a string (hex format):

HMAC Authentication

hmacSha256 - HMAC-SHA256 authentication

Generate HMAC-SHA256 for message authentication:

hmacSha512 - HMAC-SHA512 authentication

Generate HMAC-SHA512 for stronger authentication:

JWT Operations

jwtSign - Sign JWT tokens

Create and sign JWT tokens:

jwtVerify - Verify JWT tokens

Verify and decode JWT tokens:

jwtDecode - Decode JWT without verification

Decode JWT token without signature verification:

Security Best Practices

Password Hashing

API Request Signing

JWT Authentication System

Data Integrity Verification

Error Handling

Cryptographic Error Handling

Advanced Examples

Multi-factor Authentication

Secure Session Management

Best Practices

  1. Use strong secrets: Always use cryptographically strong secrets for HMAC and JWT operations
  2. Hash sensitive data: Use SHA-256 or SHA-512 for hashing sensitive information
  3. Implement proper error handling: Always check for ERROR types in cryptographic operations
  4. Use appropriate algorithms: Choose the right hashing algorithm for your security needs
  5. Validate inputs: Always validate input data before cryptographic operations
  6. Handle JWT expiration: Implement proper token expiration and refresh mechanisms
The Crypto module provides essential cryptographic tools for securing applications in Soul, enabling developers to implement robust authentication, data integrity, and secure communication features.