For encryption we use the "openssl_encrypt" function. 

$mypassword = system password + your pin
$myfile = where the encrypted data is stored
$secretArray = the data that is being encrypted

function writemyfile($myfile,$mypassword,$secretArray) {
    $json = json_encode($secretArray);
    $encryption_key = base64_decode($mypassword);
    $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
    $encrypted = openssl_encrypt($json, 'aes-256-cbc', $encryption_key, 0, $iv);
    $json2 = base64_encode($encrypted . '::' . $iv);

    if (file_put_contents($myfile, $json2)) {
    } else {
        echo "Oops! Error creating json file...";
    }
        
}