EncryptionUtil class

Utility class for handling JSON Web Token (JWT) encryption and decryption.

This class provides methods to encrypt and decrypt JSON objects using JSON Web Signature (JWS) and JSON Web Encryption (JWE) standards. It's primarily used for securing API communications and data transmission.

Security Features

  • Uses HS256 (HMAC SHA-256) algorithm for signing
  • Implements JWT standards for secure token handling
  • Provides both encryption and decryption capabilities

Usage Example

// Encrypt a JSON object
final data = {'userId': '123', 'role': 'user'};
final encrypted = EncryptionUtil.makeEncryptOfJson(data);

// Decrypt the encrypted string
final decrypted = await EncryptionUtil.makeDecryptOfJson(encrypted);

Important Notes

  • The secret key is currently hardcoded and should be externalized
  • This utility is designed for internal SDK use
  • All encryption operations are synchronous, decryption is asynchronous

Constructors

EncryptionUtil.new()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

secretKey String
The secret key used for JWT signing and encryption.
getter/setter pair

Static Methods

makeDecryptOfJson(String str) Future<Map<String, dynamic>>
Decrypts a JWT token string back to a JSON object.
makeEncryptOfJson(Map<String, dynamic> jsonObject) String
Encrypts a JSON object into a JWT token string.