php – Encrypt ini files

Question:

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:

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

Answer:

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:

W2RiX3Byb2R1Y3Rpb25dDQpob3N0ID0gZGJfcHJvZHVjdGlvbi5maWJlcjAxLmludHJhc2VydmVycw0KdHlwZSA9IG1zc3FsDQp1c2VyID0gZGJfdXNlcg0KcGFzcyA9IGRiX3Bhc3MNCm5hbWVkYiA9IGRiX25hbWU=

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