Skip to content

Commit

Permalink
Merge pull request #4 from bitbeans/master
Browse files Browse the repository at this point in the history
Add Laravel 5.2.*
  • Loading branch information
scrothers committed Mar 4, 2016
2 parents 22deddd + 1744128 commit 58b6937
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -6,8 +6,8 @@
"require": {
"php": ">=5.5.9",
"ext-libsodium": "*",
"illuminate/contracts": "5.1.*",
"illuminate/encryption": "5.1.*"
"illuminate/contracts": "5.1.*|5.2.*",
"illuminate/encryption": "5.1.*|5.2.*"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
Expand Down
2 changes: 1 addition & 1 deletion src/SodiumHasher.php
Expand Up @@ -32,7 +32,7 @@ public function needsRehash($unusedHashedValue, array $unusedOptions = [])
*/
public function make($value, array $options = [])
{
# Check if we're making a slow password
// Check if we're making a slow password
if (array_key_exists('slow', $options)) {
if (is_bool($options['slow'])) {
$slowPassword = $options['slow'];
Expand Down
24 changes: 12 additions & 12 deletions src/SodiumLibrary.php
Expand Up @@ -70,15 +70,15 @@ public static function wipeMemory($variable)
*/
public static function rawHash($data, $key = null, $length = Sodium\CRYPTO_GENERICHASH_BYTES)
{
# Test to make sure the length is within bounds
// Test to make sure the length is within bounds
if (!($length >= Sodium\CRYPTO_GENERICHASH_BYTES_MIN && $length <= Sodium\CRYPTO_GENERICHASH_BYTES_MAX)) {
throw new HashLengthException(sprintf('Hash length should be between %s and %s',
Sodium\CRYPTO_GENERICHASH_BYTES_MIN,
Sodium\CRYPTO_GENERICHASH_BYTES_MAX
));
}

# Test if a key is set, if it is, generate a key if true, or use a key if set
// Test if a key is set, if it is, generate a key if true, or use a key if set
if ($key !== null) {
if ($key === true) {
$key = Sodium\randombytes_buf(Sodium\CRYPTO_GENERICHASH_KEYBYTES_MAX);
Expand Down Expand Up @@ -137,7 +137,7 @@ public static function veryUniqueHash($data)
*/
public static function keyedHash($data, $key, $length = Sodium\CRYPTO_GENERICHASH_BYTES)
{
# Test to make sure the key is a string
// Test to make sure the key is a string
if (!is_string($key)) {
throw new KeyTypeException('keyedHash expects a string as the key');
}
Expand All @@ -155,7 +155,7 @@ public static function keyedHash($data, $key, $length = Sodium\CRYPTO_GENERICHAS
*/
public static function hashPassword($plaintext, $extraSecure = false)
{
# Create the password hash
// Create the password hash
if ($extraSecure) {
$passwordHash = Sodium\crypto_pwhash_scryptsalsa208sha256_str(
$plaintext,
Expand Down Expand Up @@ -203,10 +203,10 @@ public static function checkPassword($password, $hash)
*/
public static function encrypt($message, $key)
{
# Generate entropy to encrypt the data
// Generate entropy to encrypt the data
$nonce = self::entropy();

# Encrypt the message
// Encrypt the message
$messageEncrypted = Sodium\crypto_secretbox($message, $nonce, self::rawHash($key, null, Sodium\CRYPTO_SECRETBOX_KEYBYTES));

return sprintf('%s.%s', self::bin2hex($nonce), self::bin2hex($messageEncrypted));
Expand Down Expand Up @@ -278,13 +278,13 @@ public static function genSignKeypair()
*/
public static function messageSendEncrypt($receiving_pub, $sending_priv, $message)
{
# Create a keypair to send an encrypted message
// Create a keypair to send an encrypted message
$messageKey = Sodium\crypto_box_keypair_from_secretkey_and_publickey(
$sending_priv,
$receiving_pub
);

# Create entropy for the message
// Create entropy for the message
$nonce = self::entropy(Sodium\CRYPTO_BOX_NONCEBYTES);

$message = Sodium\crypto_box(
Expand All @@ -307,23 +307,23 @@ public static function messageSendEncrypt($receiving_pub, $sending_priv, $messag
*/
public static function messageReceiveEncrypt($receiving_priv, $sending_pub, $payload)
{
# Create a keypair to receive an encrypted message
// Create a keypair to receive an encrypted message
$messageKey = Sodium\crypto_box_keypair_from_secretkey_and_publickey(
$receiving_priv,
$sending_pub
);

# Split the payload into it's parts
// Split the payload into it's parts
$ciphertext = explode('.', $payload);

# Decrypt the message
// Decrypt the message
$plaintext = Sodium\crypto_box_open(
self::hex2bin($ciphertext[1]),
self::hex2bin($ciphertext[0]),
$messageKey
);

# Toss an exception if the decryption failed for any reason
// Toss an exception if the decryption failed for any reason
if ($plaintext === false) {
throw new DecryptionException('Malformed message or invalid MAC');
}
Expand Down

0 comments on commit 58b6937

Please sign in to comment.