J'ai utilisé la classe de chiffrement de codeigniter (framework PHP) pendant un certain temps et j'ai besoin de convertir ces fonctions en PHP en C#. Ceci afin que mon application C# puisse décrypter les données sur ma base de données de site Web et vice versa. Le problème est que j'ai récemment commencé avec C# donc je ne connais pas vraiment les noms de fonctions qui feraient la même chose que PHP.Quels sont les équivalents C# des fonctions utilisées dans ce code de chiffrement PHP?
Si je peux convertir ces 3 fonctions, je suis sûr que je serais capable de faire leurs 3 fonctions opposées moi-même car ils utilisent assez les mêmes fonctions.
Note:S'il vous plaît ne pas essayer d'utiliser ces fonctions autres que de jouer - ils ne sont pas la cryptographie forte (en fait, la méthode utilisée pourrait même être rompu avant l'invention des ordinateurs).
/**
* 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);
}
Aïe! Implémentez-vous votre propre algorithme de chiffrement? – Thomas
C'est CodeIgnitEr – quantumSoup
Et le faire en traitant le texte comme des données binaires? Double yikes! –