D
D
dantedelvengo2019-02-20 18:06:30
PHP
dantedelvengo, 2019-02-20 18:06:30

Is it possible to translate php mcrypt functions into js?

I have 2 encryption and decryption functions for the specified key in php,
one encrypts the second naturally decrypts

function code_passw($text,$key) {
$td = mcrypt_module_open ("tripledes", '', 'cfb', '');
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($td), MCRYPT_RAND);
if (mcrypt_generic_init ($td, $key, $iv) != -1) 
    {
    $enc_text=base64_encode(mcrypt_generic ($td,$iv.$text));
    mcrypt_generic_deinit ($td);
    mcrypt_module_close ($td);
    return $enc_text;
    }
 }

function decode_passw($text,$key) {
$td = mcrypt_module_open ("tripledes", '', 'cfb', '');
$iv_size = mcrypt_enc_get_iv_size ($td);
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($td), MCRYPT_RAND);     
if (mcrypt_generic_init ($td, $key, $iv) != -1) {
        $decode_text = substr(mdecrypt_generic ($td, base64_decode($text)),$iv_size);
        mcrypt_generic_deinit ($td);
        mcrypt_module_close ($td);
        return $decode_text;
}
}

they are good for simple encryption; they do not require ssl configuration and any connected modules. The question is whether they can be translated into js in terms of what I could encrypt / decrypt in php and then encrypt / decrypt in js and vice versa? googled analogues mcrypt for js is only It is on github but it is not installed not via npm and it is also not clear what is there if you download zip, is there anything else? and how can you create an analogue of these functions for js?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Ninazu, 2019-02-20
@Ninazu

What you need to google is not the implementation of mcrypt, but the implementation of a specific algorithm. In your case, tripledes
PS And how will you safely store the key in JS?)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question