Welcome to free classifieds at atnow.in

Simple way to Encryption and Decryption in Php

Please replace the secret key and secret iv as your wish!


function do_cryption( $string, $action = 'e' ) {
    // you may change these values to your own
    $secret_key = 'XXXXXXXX';
    $secret_iv = 'XXXXXXXX';

    $output = false;
    $encrypt_method = "BF";
    $key = hash( 'sha256', $secret_key );
    $iv = substr( hash( 'sha256', $secret_iv ), 0, 8 );

    if( $action == 'e' ) {
        $output = base64_encode( openssl_encrypt( $string, $encrypt_method, $key, 0, $iv ) );
    }
    else if( $action == 'd' ){
        $output = openssl_decrypt( base64_decode( $string ), $encrypt_method, $key, 0, $iv );
    }

    return $output;
}

You can use this function for dual purpose like the following.


$encrypted = 'YYYYYYYY';
echo do_cryption($encrypted,'d'); /* Its for decryption*/

$normaal= 'test';
echo do_cryption($normaal,'e'); /* Its for encryption*/

About Us

AtNow website meant a place where you can find what you are looking for. AtNow will do all that you want. All you need is to post a classified advertisement on free website and then you will get responses accordingly.
© 2025 atnow.in All rights reserved.