Skip to content

Commit

Permalink
Merge pull request #7 from legalthings/utf8-encoded-secret
Browse files Browse the repository at this point in the history
Automatically encode/decode tokens to UTF8
  • Loading branch information
svenstm committed Dec 30, 2015
2 parents fcd7423 + 77eb194 commit 79e2402
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Authorizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Authorizer
* @param string $allowedResource
* @param string $authzgen String with the format: {{certificate_url}};{{time_from}};{{time_to}}
* Time restrictions are unix timestamps, but may be omitted
* @return string $encryptedSecret
* @return string $encryptedSecret An utf8_encoded encrypted secret
*/
public static function sign($allowedResource, $authzgen)
{
Expand All @@ -50,20 +50,20 @@ public static function sign($allowedResource, $authzgen)

openssl_public_encrypt($resourceSecret, $encryptedSecret, $publicKey);

return $encryptedSecret;
return utf8_encode($encryptedSecret);
}

/**
* Decrypt an encrypted secret
*
* @param string $encryptedSecret An encrypted secret with the format:
* @param string $encryptedSecret An utf8_encoded encrypted secret with the format:
* {{resource}};{{time_from}};{{time_to}};{{hash}}
*
* @return string $decryptedSecret String with the format: {{time_from}};{{time_to}};{{checksum}}
*/
public static function decrypt($encryptedSecret)
{
openssl_private_decrypt($encryptedSecret, $decryptedSecret, self::getPrivateKey());
openssl_private_decrypt(utf8_decode($encryptedSecret), $decryptedSecret, self::getPrivateKey());

return $decryptedSecret;
}
Expand Down

0 comments on commit 79e2402

Please sign in to comment.