Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    uso intensivo di mcrypt e conseguenze sulle prestazioni

    ciao a tutti,
    di recente mi sono trovato ad usare intensivamente mcrypt in un certo punto di un applicativo dove ho necessità di criptare e decriptare le informazioni sulla carta di credito dei clienti...
    il problema principale è che su frequenti richieste sembra che php non regga molto (quando alla fine i dati sarebbero pochi) e la generazione dell'output arriva a tempi decisamente non accettabili (dai 3 secondi ai 30 secondi). Allo stesso tempo, a volte l'output viene generato istantamente, considerando che a parte decriptare i dati nel database non deve fare altro...

    il codice incriminato è questo
    Codice PHP:
    class CreditCard extends mysql
    {
        private 
    $ccId;
        private 
    $ccOwner;
        private 
    $ccType;
        private 
    $ccNumber;
        private 
    $ccExpDate;
        private 
    $encrypted 0;
        private 
    $cipher;
        private 
    $keyString;
        private 
    $iv;
        
        public function 
    __construct($id=0,$details 0)
        {
            
    parent::__construct();
            
    $this->ccId $id;
            if (
    $this->ccId != 0)
                
    $this->getCcData($details);
        }
        
        public function 
    getCcData($details)
        {
            
    $fields = ($details)?"*":"cc_type";
            
    $data mysql_fetch_assoc($this->db_query("SELECT ".$fields." FROM thebox_customers_cc WHERE cc_id = '".$this->ccId."'"));
            if (
    $details)
            {
                
    $this->ccOperationsInit();
                
    $this->ccOwner $data["cc_owner"];
                
    $this->ccNumber $data["cc_number"];
                
    $this->ccExpDate $data["cc_exp_date"];
            }
            
    $this->ccType $data["cc_type"];
        }
        
        public function 
    getExpDate($how 0)
        {
            if (
    $how == 0)
            {
                
    $date split("-",$this->ccExpDate);
                return 
    $date[1]."/".$date[0];
            }
            else
                return 
    $this->ccExpDate
        }
        
        public function 
    getCcType()
        {
            return 
    $this->ccType;
        }
        
        public function 
    ccOperationsInit()
        {
            
    $this->keyString "unastringamoltolunga";
            
    $size mcrypt_get_iv_size(MCRYPT_BLOWFISHMCRYPT_MODE_ECB);
            
    $this->iv mcrypt_create_iv($sizeMCRYPT_DEV_RANDOM);
            
    $this->cipher mcrypt_module_open(MCRYPT_BLOWFISH,'','ecb','');
        }
        
        public function 
    getDecryptedField($field)
        {
            
    mcrypt_generic_init($this->cipher$this->keyString$this->iv);
            
    $tmp mdecrypt_generic($this->cipher,base64_decode($this->$field));
            
    $tmp addcslashes($tmp"\0..\37!@\177..\377");
            
    $tmp str_replace("\\000","",$tmp);
            
    mcrypt_generic_deinit($this->cipher);
            return 
    $tmp;
        }
        
        public function 
    getEncryptedField($field)
        {
            
    mcrypt_generic_init($this->cipher$this->keyString$this->iv);
            
    $tmp base64_encode(mcrypt_generic($this->cipher,$this->$field));
            
    mcrypt_generic_deinit($this->cipher);
            return 
    $tmp;
        }
        
        public function 
    saveCcData($customerId,$ccOwner,$ccType,$ccNumber,$ccDate)
        {
            
    $this->ccOwner $ccOwner;
            
    $this->ccType $ccType;
            
    $this->ccNumber $ccNumber;
            
    $this->ccExpDate $ccDate "-01";
            
            
    $query_cc "INSERT INTO 
            thebox_customers_cc 
            VALUES 
            ('',
            '"
    .$customerId."',
            '"
    .$this->getEncryptedField("ccOwner")."',
            '"
    .$this->ccType."',
            '"
    .$this->getEncryptedField("ccNumber")."',
            '"
    .$this->ccExpDate."')";
            
    $this->db_query($query_cc,1);
            
    $this->ccId mysql_insert_id();
        }
        
        
    # getters specifici v0.2
        
    public function id() {
            return 
    $this->ccId;
        }
        
        public function 
    encryptedOwner() {
            return 
    $this->ccOwner;
        }
        
        public function 
    owner() {
            
    mcrypt_generic_init($this->cipher$this->keyString$this->iv);
            return 
    mdecrypt_generic($this->cipher,base64_decode($this->ccOwner));
        }
        
        public function 
    type() {
            return 
    $this->ccType;
        }
        
        public function 
    encryptedNumber() {
            return 
    $this->ccNumber;
        }
        
        public function 
    unshadowNumber() {
            
    mcrypt_generic_init($this->cipher$this->keyString$this->iv);
            return 
    mdecrypt_generic($this->cipher,base64_decode($this->ccNumber));
        }
        
        public function 
    number() {
            
    mcrypt_generic_init($this->cipher$this->keyString$this->iv);
            
    $unshadow mdecrypt_generic($this->cipher,base64_decode($this->ccNumber));
            return 
    "**** **** **** ".substr($unshadow,-4);
        }
        
        public function 
    expiration() {
            list(
    $y,$m) = explode('-',substr($this->ccExpDate,0,7));
            return 
    "$m/$y";
        }

    qualche suggerimento?

  2. #2
    non so per quale motivo tu voglia tenerti su db i dati delle carte di credito, con tutti i rischi immensi che ne conseguono, comunque per criptare dati su MySQL la funzione più sicura offerta dal DBMS stesso è AES_ENCRYPT / AES_DECRIPT.

  3. #3
    Originariamente inviato da skidx
    non so per quale motivo tu voglia tenerti su db i dati delle carte di credito, con tutti i rischi immensi che ne conseguono, comunque per criptare dati su MySQL la funzione più sicura offerta dal DBMS stesso è AES_ENCRYPT / AES_DECRIPT.
    dal momento che il numero di carta di credito deve rimanere a garanzia della prenotazione alberghiera fintanto che la medesima non viene cancellata o il soggiorno presso l'albergo non finisce (e quindi il cliente paga), avevo pensato poi di prendere quel file, encodarlo con zendencoder o similari e tenere una copia in chiaro da qualche parte non su internet.

    ora cmq butto un occhio a quelle due funzioni, intanto grazie...

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.