• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP openssl_encrypt函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中openssl_encrypt函数的典型用法代码示例。如果您正苦于以下问题:PHP openssl_encrypt函数的具体用法?PHP openssl_encrypt怎么用?PHP openssl_encrypt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了openssl_encrypt函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: encrypt_decrypt

 function encrypt_decrypt($action, $string)
 {
     /* =================================================
      * ENCRYPTION-DECRYPTION
      * =================================================
      * ENCRYPTION: encrypt_decrypt('encrypt', $string);
      * DECRYPTION: encrypt_decrypt('decrypt', $string) ;
      */
     $output = false;
     $encrypt_method = "AES-256-CBC";
     $secret_key = 'WS-SERVICE-KEY';
     $secret_iv = 'WS-SERVICE-VALUE';
     // hash
     $key = hash('sha256', $secret_key);
     // iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning
     $iv = substr(hash('sha256', $secret_iv), 0, 16);
     if ($action == 'encrypt') {
         $output = base64_encode(openssl_encrypt($string, $encrypt_method, $key, 0, $iv));
     } else {
         if ($action == 'decrypt') {
             $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
         }
     }
     return $output;
 }
开发者ID:An-u-p-s,项目名称:WideSecond.com,代码行数:25,代码来源:util.tools.php


示例2: encrypt

 /**
  *
  * @param string $data
  * @param string $iv
  * @param string $key
  * @return string|false
  */
 public function encrypt($data, $iv, $key)
 {
     // Max. 2^32 blocks with a same key (not realistic in a web application).
     $cipherText = openssl_encrypt($data, 'AES-128-CBC', $key, true, $iv);
     unset($data, $iv, $key);
     return $cipherText;
 }
开发者ID:puwenhan,项目名称:TCrypto,代码行数:14,代码来源:OpenSslAes128Cbc.php


示例3: encrypt

 /**
  * @param      $data
  * @param      $passphrase
  * @param null $salt        ONLY FOR TESTING
  * @return string           encrypted data in base64 OpenSSL format
  */
 public static function encrypt($data, $passphrase, $salt = null)
 {
     $salt = $salt ?: openssl_random_pseudo_bytes(8);
     list($key, $iv) = self::evpkdf($passphrase, $salt);
     $ct = openssl_encrypt($data, 'aes-256-cbc', $key, true, $iv);
     return self::encode($ct, $salt);
 }
开发者ID:blocktrail,项目名称:cryptojs-aes-php,代码行数:13,代码来源:CryptoJSAES.php


示例4: encrypt

 /**
  * Gera um novo arquivo criptografado
  * @param string $from Arquivo original
  * @param string $to   Novo arquivo
  * @return Array Retorna a classe \SplFileInfo com as informações do novo arquivo
  */
 public function encrypt($from, $to)
 {
     $iv = $this->createIv();
     $data = openssl_encrypt(file_get_contents($from), $this->cipher_method, $this->password, OPENSSL_RAW_DATA, $iv);
     file_put_contents($to, $iv . $this->password . $data);
     return new \SplFileInfo($to);
 }
开发者ID:valdeirpsr,项目名称:estudo-openssl,代码行数:13,代码来源:OpensslEncrypt.php


示例5: encrypt

 public static function encrypt($data, $password, $IV, $AAD)
 {
     if (self::useOpenSSL()) {
         $method = self::getMethod($password);
         $encrypt = openssl_encrypt($data, $method, $password, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $IV, $tag, $AAD);
     } else {
         if (self::useSO()) {
             try {
                 $cipher = \Crypto\Cipher::aes(\Crypto\Cipher::MODE_GCM, self::bitLen($password));
                 $cipher->setAAD($AAD);
                 $encrypt = $cipher->encrypt($data, $password, $IV);
                 $tag = $cipher->getTag();
             } catch (\Exception $e) {
                 //echo $e->getMessage();
                 return false;
             }
         } else {
             try {
                 list($encrypt, $tag) = AESGCM::encrypt($password, $IV, $data, $AAD);
             } catch (\Exception $e) {
                 //echo $e->getMessage();
                 return false;
             }
         }
     }
     return $encrypt . $tag;
 }
开发者ID:rnaga,项目名称:php-tls,代码行数:27,代码来源:AEADGcm.php


示例6: actionIndex

 public function actionIndex()
 {
     $user = \Yii::$app->user->identity;
     $parent = null;
     $child = null;
     if (!\Yii::$app->user->can('admin')) {
         $user->parent_id ? $parent = \common\models\User::findOne(['id' => $user->parent_id]) : '';
         $child = new \yii\data\ActiveDataProvider(['query' => \common\models\User::find()->where(['parent_id' => $user->id])]);
     } else {
         $userList = \common\models\User::find()->where(['parent_id' => null])->orderBy('id')->all();
         $tree = [];
         foreach ($userList as $key => $item) {
             $tree[] = $item;
             $branch = $this->makeTree($item->id, 0, array());
             $tree = array_merge($tree, $branch);
         }
         $userList = $tree;
         //            print_r('<pre>');
         //            print_r($userList);
         //            print_r('</pre>');
         //            die();
     }
     $crypt = openssl_encrypt($user->email, 'aes-128-ecb', '304c6528f659c77866a510d9c1d6ae5e', false);
     return $this->render('index', ['parent' => $parent, 'child' => $child, 'crypt' => $crypt, 'userList' => $userList]);
 }
开发者ID:lampyris,项目名称:referral,代码行数:25,代码来源:SiteController.php


示例7: encrypt

 public function encrypt($input, $times = 1)
 {
     for ($i = 0; $i < $times; $i++) {
         $input = openssl_encrypt($input, $this->method, $this->key, OPENSSL_RAW_DATA | OPENSSL_NO_PADDING, $this->iv);
     }
     return $input;
 }
开发者ID:xp-forge,项目名称:keepass,代码行数:7,代码来源:Cipher.class.php


示例8: run

 /**
  * Run
  */
 public function run()
 {
     // Try to get username
     $username = $this->prompt('Username', false);
     // No username, abort
     if (strlen($username) === 0) {
         $this->abort('No username provided');
     }
     // Try to get password
     $password = $this->prompt('Password', true);
     // No password, abort
     if (strlen($password) === 0) {
         $this->abort('No password provided');
     }
     // Encode username
     $encoded_username = openssl_encrypt($username, $this->app->getConfig('INI_SALT_METHOD'), $this->app->getConfig('INI_USERNAME_SALT'), 0, $this->app->getConfig('INI_USERNAME_IV'));
     // Encode password
     $encoded_password = openssl_encrypt($password, $this->app->getConfig('INI_SALT_METHOD'), $this->app->getConfig('INI_PASSWORD_SALT'), 0, $this->app->getConfig('INI_PASSWORD_IV'));
     // Create file contents
     $content = implode("\n", array('username = "' . $encoded_username . '"', 'password = "' . $encoded_password . '"', ''));
     // Target filename
     $file = sprintf('%s/%s', $this->app->getConfig('ROOT_PATH'), $this->app->getConfig('INI_FILENAME'));
     // Failed to write a file
     if (!@file_put_contents($file, $content)) {
         $this->abort('Failed to create credentials file %s', $file);
     }
     // Success
     $this->line('Credentials file %s was created for future logins', $file);
 }
开发者ID:jansav,项目名称:andyplanner,代码行数:32,代码来源:Authenticate.php


示例9: encrypt_decrypt

function encrypt_decrypt($action, $string, $key)
{
    $output = false;
    global $encryption_method;
    // Pull the hashing method that will be used
    // Hash the password
    $key = hash('sha256', $key);
    if ($action == 'encrypt') {
        // Generate a random string, hash it and get the first 16 character of the hashed string which will be ised as the IV
        $str = "qwertyuiopasdfghjklzxcvbnm,./;'\\[]-=`!@#\$%^&*()_+{}|\":?><0123456789QWERTYUIOPASDFGHJKLZXCVBNM";
        $shuffled = str_shuffle($str);
        $iv = substr(hash('sha256', $shuffled), 0, 16);
        $output = openssl_encrypt($string, $encryption_method, $key, 0, $iv);
        $output = base64_encode($output);
        // Tidy up the string so that it survives the transport 100%
        $ivoutput = $iv . $output;
        // Concat the IV with the encrypted message
        return $ivoutput;
    } else {
        if ($action == 'decrypt') {
            $iv = substr($string, 0, 16);
            // Extract the IV from the encrypted string
            $string = substr($string, 16);
            // The rest of the encrypted string is the message
            $output = openssl_decrypt(base64_decode($string), $encryption_method, $key, 0, $iv);
            return $output;
        }
    }
}
开发者ID:s3luX,项目名称:php-message-encrypt-decrypt,代码行数:29,代码来源:encdec.php


示例10: encrypt

 private function encrypt($plaintext)
 {
     // Use a random IV
     $iv = openssl_random_pseudo_bytes(16);
     // Use IV as first block of ciphertext
     return $iv . openssl_encrypt($plaintext, "AES-128-CBC", $this->encryption_key, OPENSSL_RAW_DATA, $iv);
 }
开发者ID:evgeniypetrov,项目名称:wp-ksm,代码行数:7,代码来源:class.shopify_multipass.php


示例11: encrypt_decrypt

function encrypt_decrypt($action, $string)
{
    if (!function_exists("openssl_encrypt")) {
        die("openssl function openssl_encrypt does not exist");
    }
    if (!function_exists("hash")) {
        die("function hash does not exist");
    }
    global $encryption_key;
    $output = false;
    $encrypt_method = "AES-256-CBC";
    //echo "$encryption_key\n";
    $secret_iv = 'RgX54.Ju7h';
    // hash
    $key = hash('sha256', $encryption_key);
    // iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning
    $iv = substr(hash('sha256', $secret_iv), 0, 16);
    if ($action == 'encrypt') {
        $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
        $output = base64_encode($output);
    } else {
        if ($action == 'decrypt') {
            $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
        }
    }
    return $output;
}
开发者ID:bigHosting,项目名称:RTBH,代码行数:27,代码来源:f-encryption.php


示例12: encrypt

 /**
  * Encrypt with AES-256-CTR + HMAC-SHA-512
  * 
  * @param string $plaintext Your message
  * @param string $encryptionKey Key for encryption
  * @param string $macKey Key for calculating the MAC
  * @return string
  */
 public static function encrypt($plaintext, $encryptionKey, $macKey)
 {
     $nonce = openssl_random_pseudo_bytes(16);
     $ciphertext = openssl_encrypt($plaintext, 'aes-256-ctr', $encryptionKey, OPENSSL_RAW_DATA, $nonce);
     $mac = hash_hmac('sha512', $nonce . $ciphertext, $macKey, true);
     return base64_encode($mac . $nonce . $ciphertext);
 }
开发者ID:sudhasen,项目名称:hb-ppac,代码行数:15,代码来源:aesEncryption.php


示例13: encrypt

 /**
  * Performs text encryption with openssl_encrypt and returns it as a string.<br />
  * If openssl_encrypt is not available encrypts with mcrypt, if mcrypt is not available encrypts with xor
  * 
  * @param string $text      The text to encode
  * @param string $key       [optionnal] The key to use. Default is the application key
  * @return string           The encrypted string
  */
 public static function encrypt($text, $key = null)
 {
     // Get the application key if no key is given
     if ($key === null) {
         $key = self::_getKey();
     }
     // To avoid same encoded string for the same string
     $text = self::hash($text) . '~~~' . $text;
     // If zlib is active we compress the value to crypt
     if (function_exists('gzdeflate')) {
         $text = gzdeflate($text, 9);
     }
     // Use openssl_encrypt with PHP >= 5.3.0
     if (Config::get('general.crypt_method', 'openssl') === 'openssl' && function_exists('openssl_encrypt') && in_array('BF-ECB', openssl_get_cipher_methods())) {
         $method = 'BF-ECB';
         $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($method));
         return strtr(openssl_encrypt($text, $method, $key), '+/', '-_');
     } else {
         if (function_exists('mcrypt_encrypt')) {
             $size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
             $iv = mcrypt_create_iv($size, MCRYPT_RAND);
             $crypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv);
             return rtrim(strtr(base64_encode($crypt), '+/', '-_'), '=');
         }
     }
     // ... else encrypt with xor technique
     $n = mb_strlen($text, '8bit');
     $m = mb_strlen($key, '8bit');
     if ($n !== $m) {
         $key = mb_substr(str_repeat($key, ceil($n / $m)), 0, $n, '8bit');
     }
     return base64_encode($text ^ $key);
 }
开发者ID:salomalo,项目名称:php-oxygen,代码行数:41,代码来源:security.class.php


示例14: persist

 /**
  * @inheritdoc
  */
 public function persist(\Bitpay\KeyInterface $key)
 {
     $path = $key->getId();
     $data = serialize($key);
     $encoded = bin2hex(openssl_encrypt($data, self::METHOD, $this->password, 1, self::IV));
     file_put_contents($path, $encoded);
 }
开发者ID:bitpay,项目名称:php-client,代码行数:10,代码来源:EncryptedFilesystemStorage.php


示例15: encrypt

 /**
  * Encrypt a value using AES-256.
  *
  * *Caveat* You cannot properly encrypt/decrypt data with trailing null bytes.
  * Any trailing null bytes will be removed on decryption due to how PHP pads messages
  * with nulls prior to encryption.
  *
  * @param string $plain The value to encrypt.
  * @param string $key The 256 bit/32 byte key to use as a cipher key.
  * @param string|null $hmacSalt The salt to use for the HMAC process. Leave null to use Security.salt.
  * @return string Encrypted data.
  * @throws \InvalidArgumentException On invalid data or key.
  */
 public static function encrypt($plain, $key, $hmacSalt = null)
 {
     $method = 'AES-256-CBC';
     $ivSize = openssl_cipher_iv_length($method);
     $iv = openssl_random_pseudo_bytes($ivSize);
     return $iv . openssl_encrypt($plain, $method, $key, OPENSSL_RAW_DATA, $iv);
 }
开发者ID:JesseDarellMoore,项目名称:CS499,代码行数:20,代码来源:OpenSsl.php


示例16: encrypt

 /**
  * Two way encryption: encrypt.
  *
  * @param string $data     String to be encrypted.
  * @param string $password Value phrase.
  * @param string $type     Cipher method name.
  *
  * @return string
  */
 public static function encrypt($data, $password, $type)
 {
     if ($data) {
         return openssl_encrypt($data, $type, $password, 0, Core\Config()->DB['crypt_vector']);
     }
     return '';
 }
开发者ID:weareathlon,项目名称:silla.io,代码行数:16,代码来源:crypt.php


示例17: encodeToken

 public function encodeToken()
 {
     $tokenObject = new stdClass();
     $tokenObject->token = mt_rand(100000);
     $tokenObject->time = time();
     $token = openssl_encrypt(json_encode($token), 'AES-128-ECB', CSRF_ENCRIPTION_KEY);
 }
开发者ID:yugokimura,项目名称:Automaton,代码行数:7,代码来源:Controller.php


示例18: encryptContent

 /**
  * {@inheritdoc}
  */
 public function encryptContent($data, $cek, $iv, $aad, $encoded_protected_header, &$tag)
 {
     $k = mb_substr($cek, mb_strlen($cek, '8bit') / 2, null, '8bit');
     $cyphertext = openssl_encrypt($data, $this->getMode($k), $k, OPENSSL_RAW_DATA, $iv);
     $tag = $this->calculateAuthenticationTag($cyphertext, $cek, $iv, $aad, $encoded_protected_header);
     return $cyphertext;
 }
开发者ID:spomky-labs,项目名称:jose,代码行数:10,代码来源:AESCBCHS.php


示例19: createAutologinToken

 public function createAutologinToken(TwitterUser $user)
 {
     $tokens = $user->oAuthToken . self::SEPARATOR . $user->oAuthTokenSecret;
     $keyHash = \md5($this->autoLoginKey, true);
     $encrypted = \openssl_encrypt($tokens, self::ENCRYPTION_METHOD, $keyHash, \OPENSSL_RAW_DATA);
     return \bin2hex($encrypted);
 }
开发者ID:corporateanon,项目名称:cisco-twitter,代码行数:7,代码来源:AutoLogin.php


示例20: encryptFile

 public function encryptFile($data, $filename, $key, $base64)
 {
     $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
     $iv = openssl_random_pseudo_bytes($iv_size);
     $encryptionMethod = "aes-256-cbc";
     if ($base64) {
         //if already encoded64
         if ($encryptedMessage = bin2hex($iv) . openssl_encrypt($data, $encryptionMethod, $key, 0, $iv)) {
         } else {
             return false;
         }
     } else {
         //not encoded64
         if ($encryptedMessage = bin2hex($iv) . openssl_encrypt(base64_encode($data), $encryptionMethod, $key, 0, $iv)) {
         } else {
             return false;
         }
     }
     //unset($data['filecyp']);
     if (FileWorks::writeFile($filename, $encryptedMessage) === false) {
         return false;
     } else {
         return true;
     }
 }
开发者ID:blackdragon199154,项目名称:scryptmail,代码行数:25,代码来源:FileWorks.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP openssl_error_string函数代码示例发布时间:2022-05-15
下一篇:
PHP openssl_digest函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap