Skip to content

njohns-pica9/halite_cookie

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Halite

Encrypted Cookies in PHP with Libsodium

An open source project by Paragon Initiative Enterprises.

Usage Example

Key Generation

First, you want to generate an encryption key.

$key = new \ParagonIE\Halite\Key;
$key->generate();
echo \Sodium::bin2hex($key->getKey());

(Optional) Password-Based Encryption Keys

First, store a sufficiently large random value. Then use it in conjunction with your password to derive a key.

$key = new \ParagonIE\Halite\Key;
$key->derive(
    // Password:
    'correct horse battery staple is now very shabby',
    // Salt:
    YOUR_STATIC_HALITE_PW_SALT
);

Encrypted Cookie Storage

Next, save your key somewhere you can simply do the following:

$key = new \ParagonIE\Halite\Key(\Sodium::hex2bin(SAVED_ENCRYPTION_KEY));
$cookie = new \ParagonIE\Halite\Cookie($key);
$cookie->store($key, $value);

Retrieving Values from Encrypted Cookies

Next, save your key somewhere you can simply do the following:

$value = $cookie->fetch($key);

About

Encrypted Cookie Storage powered by libsdoium

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published