Şifreleme ve şifre çözme sonra artık eşit Strings

0 Cevap php

Ben bir dize şifrelemek ve şifresini çözmek için aşağıdaki sınıfını kullanın. İki aynı dizeleri oluşturduktan sonra, ben dizelerden birini şifrelemek ve sonra şifresini. Ancak, çözülen dize (onlar dönüşüm sonra metin biçiminde özdeş bakmak bile) artık onun ikiz eşittir. Ayrıca, şifrelemek-şifresi dize ve ikizi alarak ve hex kullanımı bin2hex dönüştürdükten sonra, ben daha önce şifreli var dize sonunda sıfır bir ek numarası sadece benzer olduğunu bulmak.

Birisi ben ne yanlış yaptım işaret edebilir? Şimdiden teşekkür ederim.

class proCrypt {

public function __set( $name, $value )
{
    switch( $name)
    {
        case 'key':
        case 'ivs':
        case 'iv':
        $this->$name = $value;
        break;

        default:
        throw new Exception( "$name cannot be set" );
    }
}

/**
*
* Gettor - This is called when an non existant variable is called
*
* @access    public
* @param    string    $name
*
*/
public function __get( $name )
{
    switch( $name )
    {
        case 'key':
        return 'abcd';

        case 'ivs':
        return mcrypt_get_iv_size( MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB );

        case 'iv':
        return mcrypt_create_iv( $this->ivs );

        default:
        throw new Exception( "$name cannot be called" );
    }
}

/**
*
* Encrypt a string
*
* @access    public
* @param    string    $text
* @return    string    The encrypted string
*
*/
public function encrypt( $text )
{
    // add end of text delimiter
    $data = mcrypt_encrypt( MCRYPT_RIJNDAEL_128, $this->key, $text, MCRYPT_MODE_ECB, $this->iv );
    return bin2hex($data);
}

/**
*
* Decrypt a string
*
* @access    public
* @param    string    $text
* @return    string    The decrypted string
*
*/
public function decrypt( $text )
{
    $text = pack("H*" , $text);
    return mcrypt_decrypt( MCRYPT_RIJNDAEL_128, $this->key, $text, MCRYPT_MODE_ECB, $this->iv );
}

Sınıf} / / end

0 Cevap