Jump to content

Having problems 'encrypting' a string..?


physaux

Recommended Posts

Hey guys, I want to 'encrypt' a string. The string will only be a short, 20 character length MAX.

 

I want a function that could 'encrypt' the string, giving me OUTPUT.

I then want to process OUTPUT to give me the original string.

 

Important thing is that the OUTPUT be as short as possible. Any advice? I'm not really concerned with security, I just want the OUTPUT to not reveal what the original string is to a basic person. No sensitive information.

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/198022-having-problems-encrypting-a-string/
Share on other sites

I only have experience with one-way encryption in PHP (the md5 and sha1 algorithms), but from what I understand, there are ways of performing two-way encryption (what you want) with the mcrypt library.

 

I only have experience with one-way encryption in PHP (the md5 and sha1 algorithms), but from what I understand, there are ways of performing two-way encryption (what you want) with the mcrypt library.

 

 

[tex]Hashing  != Encryption[/tex]

MD5 and SHA1 families are not encryption in any means. As for encryption below 20 charaters, There is no way to define this behaviour. You can set a WHILE loop like so though:

$text = "...";
while(strlen($enc) < 20) {
   $enc = crypt($text, 'foo');
}

 

But you haven't stated why you want the encryption to be small. DES/3DES if a viable solution, but as for encoding BASE64 (via base64_encode/base64_decode) is a valid and compact solution if length and somewhat obfuscation is required.

 

EDIT: You may as well use B64 as you're not wanting security. It's much faster than standard encryptions, and it can be easily decoded via the functions I mentioned. An example string is:

gc3RyaW5nIG9mIHNvbWUga2luZC4=

if security is not an issue, use base64_encode() and then base64_decode()

 

should give you the results you're looking for .. no security, but a string (url?) that isn't readable.

 

[EDIT] my bad, didn't read oni-kun's post all the way through.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.