Skip to main content
With the $wsSecurity module, you can encrypt, decrypt, and hash data. It is used to protect sensitive data such as passwords, tokens, or personal information. In this section, you will learn how to use the various encryption and hash methods.

Module overview

Example / excerpt of $wsSecurity
JSON output
Note: ƒ() denotes a function. Methods overview

Templates

The security functions can be used in any template, typically for:
  • Forms with sensitive data
  • Token generation for links
  • Password processing in the registration process
  • Data transfer to external systems

Variables

No variables are available for $wsSecurity.

Methods

$wsSecurity.decrypt()

Decrypts data that was encrypted with $wsSecurity.encrypt(). Signature
$wsSecurity.decrypt(data)
Return value
string - Decrypted data in plain text.
Parameters Example that decrypts encrypted data.

$wsSecurity.encrypt()

Encrypts data with an encryption method defined in the shop configuration. The encrypted data can only be decrypted again with decrypt(). Signature
$wsSecurity.encrypt(id, data, encryptionMethod, encoding)
Return value
string - Encrypted data in WEBSALE format.
Parameters Example that encrypts data with AES-GCM.

$wsSecurity.encryptManual()

Encrypts data like encrypt(), but returns the individual components (ciphertext, salt, auth tag) separately. Useful for integration with external systems that expect a different format. Signature
$wsSecurity.encryptManual(id, data, encryptionMethod, encoding)
Return value
map - Map with the individual encryption parts.
Return fields Parameters Example that encrypts data and uses the parts individually:

$wsSecurity.hash()

Calculates a cryptographic hash value of the input data. Hash values are one-way encryptions – they cannot be converted back to the original data. Typical use case: password storage. Signature
$wsSecurity.hash(id, data, hashingMethod, encoding)
Return value
string - Hash value of the data.
Parameters Example that hashes a password with a configured method.

Actions

No actions are available for $wsSecurity. Encryption and hashing are performed directly through the module’s methods.

Examples

In this example, sensitive data is encrypted and later decrypted again.

Hash a password

In this example, a password is hashed. The hash value can later be compared with a re-hashed password.