Encrypt in javascript and decrypt in php

0

I have the following question about this php code:

<?php
class Encrypter {

    private static $Key = "dublin";

    public static function encrypt ($input) {
        $output = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5(Encrypter::$Key), $input, MCRYPT_MODE_CBC, md5(md5(Encrypter::$Key))));
        return $output;
    }

    public static function decrypt ($input) {
        $output = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5(Encrypter::$Key), base64_decode($input), MCRYPT_MODE_CBC, md5(md5(Encrypter::$Key))), "
<?php
class Encrypter {

    private static $Key = "dublin";

    public static function encrypt ($input) {
        $output = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5(Encrypter::$Key), $input, MCRYPT_MODE_CBC, md5(md5(Encrypter::$Key))));
        return $output;
    }

    public static function decrypt ($input) {
        $output = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5(Encrypter::$Key), base64_decode($input), MCRYPT_MODE_CBC, md5(md5(Encrypter::$Key))), "%pre%");
        return $output;
    }

}

$texto = "Soy un ejemplo";

// Encriptamos el texto
$texto_encriptado = Encrypter::encrypt($texto);

// Desencriptamos el texto
$texto_original = Encrypter::decrypt($texto_encriptado);

echo $texto_original;
echo $texto_encriptado;
?>
"); return $output; } } $texto = "Soy un ejemplo"; // Encriptamos el texto $texto_encriptado = Encrypter::encrypt($texto); // Desencriptamos el texto $texto_original = Encrypter::decrypt($texto_encriptado); echo $texto_original; echo $texto_encriptado; ?>

The code works well, what I want is to use the same function to encrypt in javascript and decrypt using this function in php clear using the same key I hope you understand me.

    
asked by BotXtrem Solutions 14.09.2017 в 21:56
source

1 answer

2

Look at the RSA encryption, with this in PHP you can create a public and private key on the server side and the same from the client.

There is an interesting Git link

    
answered by 16.07.2018 / 18:48
source