Вход Регистрация
Файл: sngine-v2.8/Script/includes/libs/PayPal/paypal/rest-api-sdk-php/lib/PayPal/Security/Cipher.php
Строк: 49
<?php

namespace PayPalSecurity;

/**
 * Class Cipher
 *
 * Helper class to encrypt/decrypt data with secret key
 *
 * @package PayPalSecurity
 */
class Cipher
{
    private 
$secretKey;

    
/**
     * Fixed IV Size
     */
    
const IV_SIZE 16;

    public function 
__construct($secretKey)
    {
        
$this->secretKey $secretKey;
    }

    
/**
     * Encrypts the input text using the cipher key
     *
     * @param $input
     * @return string
     */
    
public function encrypt($input)
    {
        
// Create a random IV. Not using mcrypt to generate one, as to not have a dependency on it.
        
$iv substr(uniqid(""true), 0Cipher::IV_SIZE);
        
// Encrypt the data
        
$encrypted openssl_encrypt($input"AES-256-CBC"$this->secretKey0$iv);
        
// Encode the data with IV as prefix
        
return base64_encode($iv $encrypted);
    }

    
/**
     * Decrypts the input text from the cipher key
     *
     * @param $input
     * @return string
     */
    
public function decrypt($input)
    {
        
// Decode the IV + data
        
$input base64_decode($input);
        
// Remove the IV
        
$iv substr($input0Cipher::IV_SIZE);
        
// Return Decrypted Data
        
return openssl_decrypt(substr($inputCipher::IV_SIZE), "AES-256-CBC"$this->secretKey0$iv);
    }
}
Онлайн: 1
Реклама