Bu PHP şifreleme kodu kullanılan fonksiyonların C # eşdeğerleri nelerdir?

0 Cevap

I have been using the encryption class of codeigniter (PHP framework) for a while and need to convert these functions in PHP to C#. This is so that my C# application can decrypt the data on my website database and vise versa.

Sorun Geçenlerde yani gerçekten PHP gibi aynı yapacağını işlev isimlerini bilmiyorum C # ile başlamış olması.

Ben bu 3 işlevleri dönüştürebilirsiniz varsa, ben onlar kadar yakın aynı işlevleri kullanmak gibi onların karşısında 3 fonksiyonları kendim yapmak mümkün olacaktır eminim.

Note: Please don't try to use these functions other than to play around - they are not strong cryptography (in fact, the method used could even be broken before the invention of computers).

/**
 * XOR Encode
 *
 * Takes a plain-text string and key as input and generates an
 * encoded bit-string using XOR
 *
 * @access  private
 * @param   string
 * @param   string
 * @return  string
 */
function _xor_encode($string, $key)
{
    $rand = '';
    while (strlen($rand) < 32)
    {
        $rand .= mt_rand(0, mt_getrandmax());
    }

    $rand = $this->hash($rand);

    $enc = '';
    for ($i = 0; $i < strlen($string); $i++)
    {           
        $enc .= substr($rand, ($i % strlen($rand)), 1).(substr($rand, ($i % strlen($rand)), 1) ^ substr($string, $i, 1));
    }

    return $this->_xor_merge($enc, $key);
}

    /**
 * XOR key + string Combiner
 *
 * Takes a string and key as input and computes the difference using XOR
 *
 * @access  private
 * @param   string
 * @param   string
 * @return  string
 */
function _xor_merge($string, $key)
{
    $hash = $this->hash($key);
    $str = '';
    for ($i = 0; $i < strlen($string); $i++)
    {
        $str .= substr($string, $i, 1) ^ substr($hash, ($i % strlen($hash)), 1);
    }

    return $str;
}

/**
 * Adds permuted noise to the IV + encrypted data to protect
 * against Man-in-the-middle attacks on CBC mode ciphers
 * http://www.ciphersbyritter.com/GLOSSARY.HTM#IV
 *
 * Function description
 *
 * @access  private
 * @param   string
 * @param   string
 * @return  string
 */
function _add_cipher_noise($data, $key)
{
    $keyhash = $this->hash($key);
    $keylen = strlen($keyhash);
    $str = '';

    for ($i = 0, $j = 0, $len = strlen($data); $i < $len; ++$i, ++$j)
    {
        if ($j >= $keylen)
        {
            $j = 0;
        }

        $str .= chr((ord($data[$i]) + ord($keyhash[$j])) % 256);
    }

    return $str;
}


/**
 * Hash encode a string
 *
 * @access  public
 * @param   string
 * @return  string
 */ 
function hash($str)
{
    return ($this->_hash_type == 'sha1') ? sha1($str) : md5($str);
}

0 Cevap