Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to encrypt a very short string in PHP?

Tags:

php

encryption

I would like to encrypt strings which could potentially only be about three or four characters but run to about twenty characters. A hashing function (md5, sha1, crypt etc) is not suitable as I would like to be able to decrypt the information as well. The mcrypt extension has a thoroughly daunting array of possibilities.

Does anyone have any ideas about the best way to safely encrypt short strings and why? Does anyone have any links to any material introducing a casual programmer to practical encryption scenarios?

like image 394
Shabbyrobe Avatar asked Sep 19 '08 15:09

Shabbyrobe


Video Answer


1 Answers

I like to use GnuPG for anything that needs to be encrypted on a server and then possibly decrypted either on the server or on another server (which is usually my case). This allows for an extra level of security since in my scenario the encrypting server doesn't have the key to decrypt the data. It also allows for easier manual decryption. There are a few good wrappers available for various languages (another advantage), one for PHP is GnuPGP PHP Class.

like image 189
pdavis Avatar answered Nov 15 '22 22:11

pdavis