It is necessary to solve the simplest problem: write the data encryption algorithm (strings) for php using the key.
For example:
$ data = “Text to encrypt”;
$ pass = "Sertny key";
print my_encrypt ($ data, $ pass) will display the encrypted text, which can only be decrypted by owning the key.
Of course, I would not break headlong at Habr, climb on forums and wikipedia.
Rummaged quite a lot
and I ndek
with a , and Wikipedia
There is a function mcrypt, but it requires the connection of additional libraries, there are also many ready-made standard algorithms, but there is no decent (or not) implementation for them in php. Basically, they are either on c (here's
an example ) or on perl.
There are also modules for PEAR, which is also not.
There is also a classic "University" implementation using XOR:
function x_crypt ($ data, $ key)
{
$ strlen_key = strlen ($ key);
$ sbuf = ";
for ($ i = $ n = 0, $ strlen_data = strlen ($ data); $ i <$ strlen_data; $ i ++)
{
if ($ n> = $ strlen_key) $ n = 0;
$ sbuf. = chr (ord ($ key [$ n ++]) ^ ord ($ data [$ i]));
}
return $ sbuf;
}
Encryption and decryption is performed by a single function. Explicit minus:
Source line: Hello, comrades !!, key: "Lol"
Attempt to pick up the key "Salt", the result:
ri t s looking!
It is clear that part of the ciphertext is visible, so this implementation is not very good.
')
The beauty of the ciphertext is not important;
function x_hex_decode ($ str)
{
for ($ i = 0, $ sbuf = null, $ strlen = strlen ($ str); $ i <$ strlen; $ i = $ i + 5)
{
$ sbuf. = chr (hexdec (substr ($ str, $ i + 3, 2)));
}
return $ sbuf;
}
function x_hex_code ($ str)
{
for ($ i = 0, $ sbuf = null, $ strlen = strlen ($ str); $ i <$ strlen; $ i ++)
{
$ sbuf. = chr (rand (65.70)). rand (0.9). chr (rand (65.70)). sprintf ('% X', ord (substr ($ str, $ i, 1) ))
}
return $ sbuf;
}
function decodex ($ data, $ key)
{
return x_hex_decode (x_crypt (base64_decode (gzinflate ($ data)), $ key));
}
function codex ($ data, $ key)
{
return gzdeflate (base64_encode (x_crypt (x_hex_code ($ data), $ key)), 9);
}
Where x_hex_code adds random garbage, x_hex_decode removes it, base64_encode and gzdeflate confuse the result a bit for sight, without carrying a payload.
In the process of searching, by the way, I found a curious
note :
In the Russian Federation, commercial activities related to the use of cryptographic tools are subject to mandatory licensing. Since January 22, 2008, the Decree of the Government of the Russian Federation of December 29, 2007 N 957 “On approval of provisions on licensing certain types of activities related to encryption (cryptographic) tools”, which adopted the Regulations on licensing activities on:
the distribution of encryption (cryptographic) tools
maintenance of encryption (cryptographic) tools
providing information encryption services
development, production of encryption (cryptographic) means protected using encryption (cryptographic) means of information and telecommunication systems
Is it because such (innocent) code is difficult to find?
Please help find such an algorithm / class / function.
According to the rules of the blog "Help", I undertake to lay out a working function and, possibly, describe the work.
If the habrasoobshchestvo considers the problem far-fetched or irrelevant, this habratopic will disappear, as if it did not exist.
Thank.