php – Encrypt ini files


I need a script that compiles an .ini to avoid easy reading. The file must be read with PHP. Looks like C# has a similar feature. The question is how do I do this and then read the .ini with PHP.

Example of .ini file:

host = db_production.fiber01.intraservers
type = mssql
user = db_user
pass = db_pass
namedb = db_name


If this answer is not good enough, please check my other answer to this question, rather than denying the answer that served the questioner and that may be useful for others in the future.

You can encode your result in Base64 . Stays like this:


Coding Base64 in C#:

public static string Base64Encode(string plainText) {
    var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
    return System.Convert.ToBase64String(plainTextBytes);

Decoding in C#:

public static string Base64Decode(string base64EncodedData) {
    var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData);
    return System.Text.Encoding.UTF8.GetString(base64EncodedBytes);

Encoding Base64 in PHP:

$codificada = base64_encode($string);

Decoding in PHP:

$original = base64_decode($codificada);
Scroll to Top