Download the PHP package oire/iridium without Composer

On this page you can find all versions of the php package oire/iridium. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package iridium

Iridium, a Security Library for Encrypting Data, Hashing Passwords and Managing Secure Tokens

Latest Version on Packagist Apache-2.0 License Psalm coverage Psalm level

Welcome to Iridium, a security library for encrypting data, hashing passwords and managing secure tokens! This library consists of several classes, or modules, and can be used for hashing and verifying passwords, encrypting and decrypting data, as well as for managing secure tokens suitable for authentication cookies, password reset, API access and various other tasks.

Requirements

Requires PHP 8.3 or later with PDO, _pdomysql, Mbstring, OpenSSL and Sodium enabled.

For local development, Docker and Docker Compose are used to provide a FrankenPHP + MariaDB environment.

Installation

Install via Composer:

Running Tests

Running Psalm Analysis

πŸ–‡ Base64 Handling, URL-safe Way

The Base64 module encodes data to Base64 URL-safe way and decodes encoded data.

Usage Examples

This will output:

By default, the encode() method truncates padding = signs as PHP's built-in decoder handles this correctly. However, if the second parameter is given and set to true, = signs will be replaced with tildes (~), i.e.:

This will output:

To decode the data, simply call Base64::decode():

This will output:

Methods

The Base64 class has the following methods:

πŸ— Crypt

The Crypt module is used to encrypt and decrypt data. Note! Do not use this for managing passwords! Passwords must not be encrypted, they must be hashed instead. To manage passwords, use the Password module (see below). Currently the Crypt module supports only shared key encryption, i.e., encryption and decryption is performed with one single key.

As of v3.0, Crypt uses AES-256-GCM (authenticated encryption with associated data) for new encryptions. Data encrypted with the previous AES-256-CTR + HMAC-SHA384 scheme (v1) is still transparently decrypted for backward compatibility. The swapKey() method automatically migrates v1 ciphertext to v2 (GCM) when re-encrypting.

πŸ”‘ Shared Key

This objects holds a key used to encrypt and decrypt data with the Crypt module. First you need to create a key and save it somewhere (i.e., in a .env file):

This will output a readable and storable string, something similar to this:

SharedKey Methods

Generally, you will only need the getKey() method for storing the key in a safe place. You can also benefit from using the __toString() method and treat the key object as a string. However, let's describe all the methods for the sake of completeness:

Derived Keys

The DerivedKeys object holds the keys derived by the deriveKeys() method of the shared key. Again, in 99,(9)% of cases you don't want to use it, but let's enumerate its methods.

Crypt Usage Examples

If you created a shared key as shown above, you can encrypt your data with this key:

That's it, you may store your encrypted data in a database or perform other actions with them. To decrypt the data with the same key, use the following:

Exceptions

Crypt throws EncryptionException, DecryptionException and sometimes a more general CryptException. If something is wrong with the key, a SharedKeyException is thrown.

Methods

The Crypt class has the following methods:

πŸ”’ Password

The Password class is used to hash passwords and verify that a provided hash is valid.

Usage Examples

To lock, i.e., hash a password, use the following:

Then you can store your password in the database. To check whether a provided password is valid, use the following:

To check if a stored password hash needs rehashing (for example, after PHP upgrades its default algorithm parameters):

You can also use Crypt to reencrypt the password with another key, just use Crypt::swapKey() and provide your password hash to it. Remember that you cannot "decrypt" a password and obviously must not store unhashed plain-text passwords, this poses a huge security risk.

Methods

The Password class has the following methods:

πŸͺ SplitToken, Simple Yet Secure Token Suitable for Authentication Cookies and Password Recovery

SplitToken is a class inside Iridium that can be used for generating and validating secure tokens suitable for authentication cookies, password recovery, API keys and various other tasks.

The Split Tokens Concept

You can read everything about the split tokens authentication in this 2017 article by Paragon Initiatives. Iridium implements the idea outlined in that article in PHP.

Storage Interface

As of v3.0, SplitToken is decoupled from PDO via the TokenStorageInterface. The library ships with PdoTokenStorage for MySQL/MariaDB, but you can implement the interface for any backend.

TokenStorageInterface Methods

ListableTokenStorageInterface

Single-use tokens such as password reset links never need to be enumerated: the user clicks the link, and the token is spent. Long-lived tokens are different. If you issue personal access tokens for an API, the owner has to be able to see what they issued and revoke one of them, and neither is possible with the methods above. ListableTokenStorageInterface extends TokenStorageInterface with the four operations that need:

StoredToken is a readonly value object carrying id, userId, selector, tokenType, additionalInfo, expirationTime, createdAt and lastUsedAt, plus isEternal(), isExpired() and getExpirationDate(). It deliberately carries neither the token nor the verifier: a listing is something you show a user, and neither of those halves belongs on a screen.

Both bundled storages implement this interface. It needs two extra columns β€” see Create a Table below.

PdoTokenStorage

DoctrineDbalTokenStorage

For applications already using Doctrine. doctrine/dbal is a suggested dependency only, so the library itself stays dependency-free β€” install it yourself if you use this storage.

Usage Examples

Each time you use SplitToken::create() to generate a new token or SplitToken::fromString() to instantiate a new SplitToken object from a user-provided token, you need to provide a TokenStorageInterface instance. The bundled PdoTokenStorage wraps a PDO connection.

Create a Table

First you need to create the iridium_tokens table. For MySQL/MariaDB the statement is as follows:

If you want to use ListableTokenStorageInterface, add two more columns:

You may need to adjust the syntax to suit your particular database driver, as well as add foreign key constraints to match your users table.

Create a Token

First you need to create a token. There are some parameters you can set, but only the storage is required, all the other parameters have default values.

To create a token for user with ID of 123 and with token type of 3 expiring in half an hour, and store it into the database, do the following. You can of course use named arguments:

Use $splitToken->getToken() to actually get the newly created token as a string. If you want to create a non-expirable token, explicitly set expirationTime to null.

Set and Validate a User-Provided Token

If you received an Iridium token from the user, you also need to instantiate SplitToken and validate the token. To do this, use SplitToken::fromString() instead of create(). You don't need to set all the properties as their values are taken from the database. This method takes three parameters: the token as string, a TokenStorageInterface instance, and optionally the additional info decryption key as Iridium shared key.

Note! As of v3.1 an expired token is rejected, and so is a revoked one, because revocation is stored as an expiration in the past. Before v3.1 fromString() returned such tokens and left the check to you, which meant that a caller who did not know to call isExpired() authenticated revoked tokens by default.

If you need the object in order to report on it β€” to tell a user when their password reset link died, say β€” pass allowExpired: true. Never do this to authenticate:

Revoke a Token

After a token is used once for authentication, password reset and other sensitive operation, is expired or compromised, you must revoke, i.e., invalidate it. If you use Iridium tokens as API keys, tokens for unsubscribing from email lists and so on, you can make your token eternal or set the expiration time far in the future and not revoke the token after first use, certainly. If an eternal token is compromised, you must revoke it, also. The revokeToken() method returns a SplitToken instance with the token-related parameters set to null. When revoking a token, you have two possibilities:

Revoking by Selector

revokeToken() is an instance method, and the only way to obtain an instance is fromString(), which needs the plaintext token. For a long-lived token that plaintext is exactly what nobody has any more: the owner was shown it once and told it would never be shown again. Revoking such a token from a management screen is therefore impossible through revokeToken().

Use the static revokeBySelector() instead, with a selector taken from getSelector() or from a listing:

Clear Expired Tokens

From time to time you will need to delete all expired tokens from the database to reduce the table size and search times. There is a method to do this. It is static, so you have to provide your TokenStorageInterface instance as its parameter. It returns the number of tokens deleted from the database.

Note! This deletes revoked tokens too, since revocation is stored as an expiration in the past. Running it erases the record of what was revoked and when. Where that history matters β€” and for API keys it usually does β€” use a cutoff instead, which sweeps only what expired long enough ago to be uninteresting:

Notes on Expiration Times

Error Handling

SplitToken throws two types of exceptions:

Methods

Below all of the SplitToken public methods are outlined.

Changes and Bugfixes

See changelog.

Contributing

All contributions are welcome. Please fork, make a feature branch, hack on the code, commit, push your branch and send a pull request.

Before committing, don't forget to run all the needed checks, otherwise the CI will complain afterwards:

If PHP CS Fixer finds any code style errors, fix them in your code. When your pull request is submitted, make sure all checks passed on CI.

License

Copyright Β© 2021-2026 AndrΓ© Polykanine, Oire Software. This software is licensed under the Apache License, Version 2.0. See LICENSE for details.


All versions of iridium with dependencies

PHP Build Version
Package Version
Requires php Version >=8.3
ext-mbstring Version *
ext-openssl Version *
ext-pdo Version *
ext-sodium Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package oire/iridium contains the following files

Loading the files please wait ...