physaux Posted April 8, 2010 Share Posted April 8, 2010 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 More sharing options...
tmallen Posted April 8, 2010 Share Posted April 8, 2010 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. http://php.net/manual/en/book.mcrypt.php http://www.phpro.org/classes/Two-Way-Encryption-With-PHP-Mcrypt.html Link to comment https://forums.phpfreaks.com/topic/198022-having-problems-encrypting-a-string/#findComment-1039077 Share on other sites More sharing options...
oni-kun Posted April 9, 2010 Share Posted April 9, 2010 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. http://php.net/manual/en/book.mcrypt.php http://www.phpro.org/classes/Two-Way-Encryption-With-PHP-Mcrypt.html [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= Link to comment https://forums.phpfreaks.com/topic/198022-having-problems-encrypting-a-string/#findComment-1039227 Share on other sites More sharing options...
mrMarcus Posted April 9, 2010 Share Posted April 9, 2010 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. Link to comment https://forums.phpfreaks.com/topic/198022-having-problems-encrypting-a-string/#findComment-1039233 Share on other sites More sharing options...
physaux Posted April 9, 2010 Author Share Posted April 9, 2010 thanks alot guys, it works! Link to comment https://forums.phpfreaks.com/topic/198022-having-problems-encrypting-a-string/#findComment-1039249 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.