final public static function encrypt(string $plainText, string $key = null, string $method = null): string
    {
        if ($method === null) {
            $method = static::getMethod();

            if (!in_array($method, openssl_get_cipher_methods())) {
                throw new CryptException("OpenSSL method={$method} defined in application config is not available");
            }
        } else {
            if (!in_array($method, openssl_get_cipher_methods())) {
                throw new CryptException("Passed OpenSSL method={$method} is not available");
            }
        }

        $key = Util::str2hex($key ?? Application::getKey());
        $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($method));

        $encrypted = @openssl_encrypt($plainText, $method, $key, 0, $iv);

        if ($encrypted === false) {
            throw new CryptException('Unable to encrypt your plain text; check your openssl_default_method in application config');
        }

        return $encrypted . ':' . bin2hex($iv);
    }