Encrypt authentication token and store it in session/cache.

@param array $token

@return void
175714
public function put($token)
    {
        $encryptedToken = $this->encryptor->encrypt($token);

        $this->storage->put('token', $encryptedToken);
    }
574357
public static function authenticateWithToken($token) {
    $pkeyResource = openssl_pkey_new(array(
      "digest_alg" => "sha256",
      "private_key_bits" => 2048
    ));

    openssl_pkey_export($pkeyResource, $generatedPrivateKey);

    $pkeyResourceDetails = openssl_pkey_get_details($pkeyResource);
    $generatedPublicKey = $pkeyResourceDetails["key"];

    $requestResult = Request::post("/g_business/v1/authentication_keys", array(
      "body" => array(
        "public_key" => $generatedPublicKey,
        "token" => $token
      )
    ));

    self::$privateKey = $generatedPrivateKey;
    self::$publicKey = $generatedPublicKey;
    self::$keyId = $requestResult->key_id;

    $returnClass = new ApiAuthentication();
    $returnClass->privateKey = $generatedPrivateKey;
    $returnClass->publicKey = $generatedPublicKey;
    $returnClass->keyId = $requestResult->key_id;
    return $returnClass;
  }
141729
public function set($token, $type)
    {
        if ($type != 'request_token' && $type != 'access_token') {
            throw new \Dropbox\Exception("Expected a type of either 'request_token' or 'access_token', got '$type'");
        } else {
            $token = $this->encrypt($token);
            $_SESSION[$this->namespace][$this->userID][$type] = $token;
        }
    }
1001788
public function handlesToken($token)
    {
        return (
            isset($this->tokensHandled)
            && is_array($this->tokensHandled)
            && in_array($token, $this->tokensHandled)
        );
    }
838359
protected function handleText(array $token)
    {

        $node = $this->createNode('text', $token);
        $node->value = $token['value'];
        $node->level = $token['level'];
        $node->escaped = $token['escaped'];

        if ($this->current) {

            $this->current->append($node);
        } else
            $this->current = $node;
    }
187212
public function invalidateToken(Token $token)
    {
        $this->tokenCache->remove($token->getHash());

        $this->logger->log(sprintf('Deleted token %s.', $token->getIdentifier()), LOG_INFO);
    }
700251
protected function encrypt($token)
    {
        // Serialize the token object
        $token = serialize($token);
        
        // Encrypt the token if there is an Encrypter instance
        if ($this->encrypter instanceof Encrypter) {
            $token = $this->encrypter->encrypt($token);
        }
        
        // Return the token
        return $token;
    }
15586
public static function decodeToken($token) {
        global $CFG;
        $plain = AesCtr::decrypt($token, $CFG->websocket_secret, 256) ;
        $pieces = explode('::', $plain);
        if ( count($pieces) != 4 ) return false;
        return $plain;
    }
420462
final protected static function RawVerify( string $token ) : bool {
        
        self::InitSession( );
        
        $key = self::GetSessionKey( );
        foreach( $_SESSION[ $key ] as $i => $t ) {
            if( hash_equals( $t[self::key_Token], $token ) ) {
                unset( $_SESSION[ $key ][ $i ] );
                return true;
            }
        }
        
        return false;
        
    }
854874
public function setSessionTokens($token, $tokenSecret = null)
    {
        $this->session->set(self::SESSION_TOKEN_KEY, $token);
        $this->session->set(self::SESSION_TOKEN_SECRET_KEY, $tokenSecret);
    }
833481
public function setAccessToken($token)
    {
        if (!is_object($token) && $token !== null) {
            $token = $this->createToken($token);
        }
        $this->_accessToken = $token;
        $this->saveAccessToken($token);
    }
1023430
private function setToken(array $token)
    {
        if (is_a($this->container, '\\ArrayAccess')) {
            $this->container['token'] = $token;
            return;
        }

        $this->container->set('token', $token);
    }
1003109
public function validateToken($token)
    {
        $tokenChecksum = Mage::getSingleton('ecomdev_varnish/cookie')->get(self::COOKIE_TOKEN_CHECKSUM);
        if ($tokenChecksum === $this->getChecksum(array('token' => $token))) {
            return true;
        }

        return false;
    }
102697
public function authenticate(TokenInterface $token)
    {
        if (false === $this->supports($token)) {
            throw new SecurityException('Invalid token provided', SecurityException::UNSUPPORTED_TOKEN);
        }

        try {
            $user = $this->userProvider->loadUserByUsername($token->getUsername());
            $secret = $user->getPassword();
            if ($this->encoderFactory) {
                try {
                    $encoder = $this->encoderFactory->getEncoder($user);

                    if ($encoder instanceof PlaintextPasswordEncoder) {
                        $secret = md5($secret);
                    } elseif ($encoder instanceof MessageDigestPasswordEncoder) {
                        // $secret is already md5 encoded
                        // NB: only md5 algo without salt is currently supported due to frontend dependency
                    } else {
                        // currently there is a dependency on md5 in frontend so all other encoders can't be supported
                        throw new \RuntimeException('Encoder is not supported: '.get_class($encoder));
                    }
                } catch (\RuntimeException $e) {
                    // no encoder defined
                    $secret = md5($secret);
                }
            } else {
                // no encoder - still have to encode with md5
                $secret = md5($secret);
            }

            $this->checkNonce($token, $secret);
        } catch (\Exception $e) {
            $this->clearNonce($token);
            throw $e;
        }

        $validToken = new BBUserToken($user->getRoles());
        $validToken
            ->setUser($user)
            ->setNonce($token->getNonce())
            ->setCreated(new \DateTime())
            ->setLifetime($this->lifetime)
        ;

        $this->writeNonceValue($validToken);

        return $validToken;
    }
327551
public function verify(Token $token, VerificationContext $verificationContext = null): void
    {
        if (null === $verificationContext) {
            $verificationContext = new VerificationContext($this->getEncryption());
        }

        if ($this->getAudience()) {
            $verificationContext->setAudience($this->getAudience());
        }

        try {
            $this->getLib()->verify($token, $verificationContext);
        } catch (\Exception $exception) {
            throw new VerifyTokenException('Token did not pass the verification', $exception->getCode(), $exception);
        }
    }
887376
public static function verify($token)
  {
    $userToken = Password::where('token', $token)->first();

    if ($userToken == null) {
      return false;
    }

    if ($userToken->created_at->diffInMinutes() <= config('app.reset_token.expire')) {
      if (Session::has('token')) {
        if (Session::key('token') == $userToken->token) {
          return true;
        }
        else {
          Session::delete('token');
          return false;
        }
      }
      else {
        return false;
      }
    }

    $userToken->delete();
    return false;
  }
26609
public function WXBizMsgCrypt($token, $encodingAesKey, $appId)
	{
		$this->token = $token;
		$this->encodingAesKey = $encodingAesKey;
		$this->appId = $appId;
	}