Search code examples
phpmysqlmaskingpassword-encryption

Masked password in php


Hi There is one xml in which i am assigning the value of password that i get by third party . I want to masked in it. I want to hide that password. Code is in php. Is it possible to mask password in php ?


Solution

  • You can encrypt the password using the following:

    define('SALT', 'atopsecretphrase'); 
    
    function encrypt($text) 
    { 
        return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, SALT, $text, MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND)))); 
    } 
    
    function decrypt($text) 
    { 
        return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, SALT, base64_decode($text), MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND))); 
    } 
    
    $encryptedmessage = encrypt("mypassword"); 
    echo decrypt($encryptedmessage);