protected static function SocialApi::encryptToken in Social API 3.x
Same name and namespace in other branches
- 8.2 src/Entity/SocialApi.php \Drupal\social_api\Entity\SocialApi::encryptToken()
Returns the encrypted token.
Parameters
string $token: The plain-text token provided by the provider.
Return value
string The encrypted token.
2 calls to SocialApi::encryptToken()
- SocialApi::create in src/
Entity/ SocialApi.php - Constructs a new entity object, without permanently saving it.
- SocialApi::setToken in src/
Entity/ SocialApi.php - Sets the encrypted, serialized token.
File
- src/
Entity/ SocialApi.php, line 72
Class
- SocialApi
- Defines a base class for Social API content entities.
Namespace
Drupal\social_api\EntityCode
protected static function encryptToken($token) {
$key = static::getEncryptionKey();
// Remove the base64 encoding from our key.
$encryption_key = base64_decode($key);
// Generates an initialization vector.
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
// Encrypts the data using AES 256 encryption in CBC mode using our
// encryption key and initialization vector.
$encrypted = openssl_encrypt($token, 'aes-256-cbc', $encryption_key, 0, $iv);
// The $iv is just as important as the key for decrypting, so save it with
// our encrypted data using a unique separator (::).
return base64_encode($encrypted . '::' . $iv);
}