当前位置: 首页>>代码示例>>PHP>>正文


PHP Encryption::base64Decode方法代码示例

本文整理汇总了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=='));
 }
开发者ID:enyo,项目名称:rincewind,代码行数:5,代码来源:EncryptionTest.php

示例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;
 }
开发者ID:enyo,项目名称:rincewind,代码行数:74,代码来源:Ssl.php


注:本文中的Encryption::base64Decode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。