Skip to content

rikby/crypter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

String Crypter

Simple tool for encrypting/decrypting a string. It based upon system ID.

$ composer require rikby/crypter

Using example:

/**
 * Class Password
 */
class Password extends Crypter implements CrypterInterface
{
    /**
     * Get password
     *
     * @param string $trackerType
     * @return null|string
     * @throws \Exception
     */
    public function getPassword($trackerType)
    {
        try {
            //get saved encrypted password
            $password = SomeClass::getPostPassword();
            if (!$password) {
                return null;
            }

            return $this->decrypt($password) ?: null;
        } catch (\Exception $e) {
            throw new UserException('Cannot get password of tracker.', 0, $e);
        }
    }

    /**
     * Replace strange \000 character
     *
     * {@inheritdoc}
     */
    public function decrypt($string, $key = null)
    {
        $password = parent::decrypt($string, $key);

        /**
         * Unknown bug in PhpStorm
         * Only PHPStorm adds \0 to the tail of password
         * Perhaps PHP versions conflict
         */
        return rtrim($password, "\000");
    }
}

About

Simple tool for encrypting/decrypting a string. It based upon system ID.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages