📝Crypto
The module that handles encryption and decryption.
Imports
Environment Variables
CRYPTO_PASSWORD
Password used in the encryption and decryption process.
Write .env
file with environment variable. Below has an example:
Application Variables
crypto_driver
redis
, sqlite
, fs
The driver used for store metadata of encryption.
How to set variable
You can set the application variable in your main module and/or in the module that will inject the service.
Method of Use
To use this module, you need to inject it into the desired service.
Injecting the module into our service.
With dependencies
You will need to inject the following interfaces.
IConfigurationService
IValidatorRegexpService
IStringExService
IRedisService
IDebugService
ISqliteService
IRandomService
Properties
get _driver
private
The driver used to store the metadata of encryption.
get _isRedis
private
Check if the driver is Redis.
get _isSqlite
private
Check if the driver is SQLite.
get _isFileSystem
private
Check if the driver is FileSystem.
get _fileSystemPath
private
Returns the path of the file in disk of the FileSystem.
get _fileSystemExistsData
private
Check if the file exists in disk of the FileSystem.
get _fileSystemEncode
private
Returns the encode of the file in disk of the FileSystem.
Methods
_createTable
private
It create the table in the SQLite database.
_fileSystemWrite
private
It writes the data in the file in disk of the FileSystem.
_fileSystemRead
private
It reads the data in the file in disk of the FileSystem.
_fileSystemDataParse
private
It parses the data in the file in disk of the FileSystem.
_createFileSystem
private
It creates the file in disk of the FileSystem.
_fileSystemAppend
private
It append data in the file in disk of the FileSystem.
_fileSystemFind
private
It finds a key in the file in disk of the FileSystem.
_fileSystemDelete
private
It deletes a key in the file in disk of the FileSystem.
_insert
private
It inserts a key and a value in the SQLite database.
_find
private
It find a key in the SQLite database.
_del
private
It deletes a key from the database.
_createHash
private
It takes a string, creates a hash of it, and returns the first 32 characters of the hash.
_getHash
private
It creates a hash of a random string.
_serialize
private
It takes a string, hashes it, and returns the hash.
_compress
private
It takes a value of type T, converts it to a string, compresses it, and returns the compressed string.
_decompress
private
It takes a string, decompresses it, and returns the result as a generic type.
_save
private
It saves a value to the cache.
_saveBuffer
private
It saves a buffer to the cache.
_load
private
It loads a value from the cache, decompresses it, and returns it.
_loadBuffer
private
It loads a buffer from the cache.
_delete
private
It takes a variable number of strings, serializes them, and then passes them to the Redis client's del function.
encrypt
public
It encrypts a string using a password and saves the encrypted string, the initialization vector, and the authentication tag to the database.
decrypt
public
It decrypts the encrypted string using the password and the IV and the tag.
Last updated