In my application i plan to implement the encryption which is corresponding to the mcrypt in PHP backend. I need a functionality in ionic 3 which gives output as shown in php sample script
<?php
/* Open the cipher */
$td = mcrypt_module_open('rijndael-256', '', 'ofb', '');
/* Create the IV and determine the keysize length, use MCRYPT_RAND
* on Windows instead */
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_DEV_RANDOM);
$ks = mcrypt_enc_get_key_size($td);
/* Create key */
$key = substr(md5('very secret key'), 0, $ks);
/* Intialize encryption */
mcrypt_generic_init($td, $key, $iv);
/* Encrypt data */
$encrypted = mcrypt_generic($td, 'This is very important data joker');
echo "encrypted value: ".$encrypted;
/* Terminate encryption handler */
mcrypt_generic_deinit($td);
/* Initialize encryption module for decryption */
mcrypt_generic_init($td, $key, $iv);
/* Decrypt encrypted string */
$decrypted = mdecrypt_generic($td, $encrypted);
/* Terminate decryption handle and close module */
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
/* Show string */
echo trim($decrypted) . "\n";
?>
<giant-blink>BACK AWAY FROM THE COMPUTER</giant-blink>
The road to hell is paved with the bones of amateurs who have attempted to build their own encrypted communication protocols. Do not add yours to the pile.
DO NOT use MD5 for anything.
DO NOT burn secrets into your app binary.
DO NOT use any homebrew cryptographic protocol.
DO use HTTPS.
DO use JSON Web Tokens.
The above post is not a “solution” to anything and should emphatically NOT be emulated by anybody coming across this thread. It displays remarkable irresponsibility and willful ignorance of an extremely important topic. Promoting it to anybody as providing any meaningful degree of security is a gross misrepresentation of reality.