本文整理汇总了PHP中Encryption::base64Decode方法的典型用法代码示例。如果您正苦于以下问题:PHP Encryption::base64Decode方法的具体用法?PHP Encryption::base64Decode怎么用?PHP Encryption::base64Decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Encryption
的用法示例。
在下文中一共展示了Encryption::base64Decode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testBase64Decode
public function testBase64Decode()
{
self::assertSame('!!?*!~Za_-c@#$2üäas!', Encryption::base64Decode('ISE_KiF-WmFfLWNAIyQyw7zDpGFzIQ'));
// self::assertSame('3_-4bbc2_-3', Security::sanitizeBase64('3/+4bbc2/+3=='));
}
示例2: decrypt
/**
* Verifies that a sigend + encrypted string is valid and returns the
* decrypted string.
*
* This method...
*
* 1. ...takes the iv from the beginning of the string
* 2. ...does a base64_decode of the rest of the string
* 3. ...checks that the ssl encryption is correct (decrypts the string with
* the correct cipher and password).
* 4. ...checks that the salt is present and at the beginning of the the
* string.
* 5. ...removes the random characters from the end of the string
*
*
* BE CAREFUL!!!
*
* Never let the message from the EncryptionException be visible to the user.
* This could result in a security risk.
* The exception message is only for debugging purpose.
*
* If the data that has been encrypted wasn't a string, it gets serialized by
* this method.
*
* @param string $encryptedData
* @return mixed
* @throws EncryptionException
*/
public function decrypt($encryptedData)
{
$encryptedData = explode('.', $encryptedData);
if (count($encryptedData) !== 1 && count($encryptedData) !== 2) {
throw new EncryptionException('The encrypted string did not have a correct iv.');
}
if (count($encryptedData) === 1) {
// No IV has been chosen
$iv = '';
$encryptedData = Encryption::base64Decode($encryptedData[0]);
} elseif (count($encryptedData) === 2) {
// IV present
$iv = $encryptedData[0];
if (!$iv) {
throw new EncryptionException('IV was empty.');
}
$encryptedData = Encryption::base64Decode($encryptedData[1]);
}
if (!$encryptedData) {
throw new EncryptionException('Encrypted string is not base64.');
}
$iv = $this->padIv($iv, $this->cipherIvLength);
$decrypted = openssl_decrypt($encryptedData, $this->cipher, $this->password, true, $iv);
if ($decrypted === false) {
throw new EncryptionException('Encrypted string is not correctly openssl encrypted.');
}
$saltLength = strlen($this->salt);
if (substr($decrypted, 0, $saltLength) !== $this->salt) {
throw new EncryptionException('Encrypted string does not contain the salt.');
}
$dataInfoLength = 2;
$dataInfo = substr($decrypted, $saltLength, $dataInfoLength);
if ($dataInfo !== self::SERIALIZE_NONE . '-' && $dataInfo !== self::SERIALIZE_PHP . '-' && $dataInfo !== self::SERIALIZE_JSON . '-') {
throw new EncryptionException('Encrypted string does not contain data information.');
}
$data = substr($decrypted, $saltLength + $dataInfoLength, strlen($decrypted) - $saltLength - $dataInfoLength - $this->nonceChars);
switch ($dataInfo) {
case self::SERIALIZE_PHP . '-':
$data = @unserialize($data);
break;
case self::SERIALIZE_JSON . '-':
$data = @json_decode($data, true);
break;
}
return $data;
}