Stay at home discount

PHP Encryption For Generating Fixed Length Encryption Strings

September 13, 2020 - By 

Let’s start with the actual PHP function:

1. function XOREncryption($InputString, $KeyPhrase){

2.   

3.     $KeyPhraseLength = strlen($KeyPhrase);

4.   

5.     // Loop trough input string

6.     for ($i = 0; $i //SALT

$salt = ‘my_special_phrase’;

//ENCRYPT

$crypted = base64_encode(XOREncryption(‘my string’, $salt));

echo “Encrypted: ” . $crypted . “
“;

 The variable ‘ $salt ‘ plays a crucial role here.  It is essentially the ‘key’ to your encrypted string. The salt value will always generate the same values when the same mathematics are applied to it.  It provides the constant needed to generate randomness.  This goes to say that if someone uses the salt that was used to generate the encryption and applies the same mathematics they can undo or reverse the encrypted string back into the original string text.

In order to decrypt an encrypted string that was generated by using this function use the invoccation code below:

//SALT

$salt = ‘my_special_phrase’;

//DECRYPT

$decrypted  = XOREncryption(base64_decode($crypted), $salt);

echo “Decrypted: ” . $decrypted;

As long as I use the same salt I can reverse an encrypted string that was encrypted with this function.

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments

Leave a Reply

Do NOT follow this link or you will be banned from the site!
x

We use cookies to give you the best online experience. By agreeing you accept the use of cookies in accordance with our cookie policy.

I accept I decline Privacy Center
0
Would love your thoughts, please comment.x
()
x