PHP Encryption For Generating Fixed Length Encryption Strings
- September 23, 2022
- SEO Service Provider
[ad_1]
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.
Related
About us and this blog
We are a digital marketing company with a focus on helping our customers achieve great results across several key areas.
Request a free quote
We offer professional SEO services that help websites increase their organic search score drastically in order to compete for the highest rankings even when it comes to highly competitive keywords.
Subscribe to our newsletter!
More from our blog
See all postsRecent Posts
- Dominating the Digital Landscape: SEO Service Provider in Sri Lanka September 2, 2023
- Inspiring Your Journey: Harnessing the Power of Motivational Videos June 13, 2023
- YouTube Backlink Service: Benefits and Risks March 10, 2023