-2

I am coding a solution that requires data to be encrypted in to strings of the same length.

The solution needs to meet this criteria:

  • Easy implementation in PHP
  • Creates same length output regardless of length(similar to MD5) edit: Time to redefine. Creates the same output length from the same input length.
  • Can encrypt a string(disregard this)
  • Public key encryption is fine, I will keep the key stored privately no matter what, and it won't be distributed.

Basically I just need some type of encryption that will handle this, MD5 would be the answer but I need to decrypt everything too.

I have spent hours looking this up. I haven't been able to find anything.

Tom
  • 141
  • 1
  • 10

2 Answers2

2

Can encrypt a string

If it's to be called encryption, it must be reversible, therefore..

Creates same length output regardless of length(similar to MD5)

is not possible.

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
1

I suggest you to look the MCrypt extension for php, there are plenty of cypher availables and already implemented. However i don't think they can meet your second criteria (because they add padding if necessary).

Or you can try to implement a CTS algorithm which will allow you to meet your second criteria. However CTS brings complexity. There is already a post on CTS in SO: Cipher Text Stealing Algorithms - Which one is correct?

Edit: If you can't use Mcrypt and are ok with cypher that use block to encrypt (thus padd the original data if necessary), you can use this implementation of the AES cypher: http://www.movable-type.co.uk/scripts/aes-php.html Regards

Community
  • 1
  • 1
grifos
  • 3,321
  • 1
  • 16
  • 14
  • Thanks, I believe this should work too. It in fact may even might be a little bit better. The good thing is I have the next month to write the PHP for the encyption that I am going to be doing. I will read up on this tonight and then crash in the morning. – Tom Mar 25 '12 at 03:35