3

Is it possible to specify a lowercase only output when using Mcrypt?

This is a sample of my code used to encrypt:

 public  function encode($value){ 
      if(!$value){return false;}
      $text = $value;
      $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
      $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
      $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->skey, $text, MCRYPT_MODE_ECB, $iv);
      return trim($this->safe_b64encode($crypttext)); 
  }

The reason for this is that I need a lowercase only encrypted string.

Thank you,

Chris.

EDIT

I am creating a reply via email app that lets users reply to a thread via the notification email. I am using a unique encrypted string as the reply email to identify it. Mcrypt outputs upper and lowercase strings. This works fine for Gmail and Outlook, but Hotmail converts the reply address string to lowercase which then errors when I decrypt. I therefore need the output string from the func above to be lowercase only.

Kit
  • 4,095
  • 7
  • 39
  • 62
  • Are you sure you will be able to decrypt *broken* data back? – zerkms Mar 14 '11 at 11:46
  • If it is created only with lowercase characters maybe? – Kit Mar 14 '11 at 11:47
  • Saying you need lowercase output because you need lowercase output is not a reason. This just sounds like you've made the arbitrary decision to have lowercase output and made things unnecessarily complicated. – Brad Mace Mar 14 '11 at 11:52
  • @bemace - please see the edit for the reason. – Kit Mar 14 '11 at 11:57

2 Answers2

3

You can't make mcrypt_encrypt give you all lowercase output, but you can avoid uppercase letters in the email address you send out. Either find 26 other characters not already used in mcrypt's output (probably won't be able to find that many) to replace upper case letters with, or just lowercase each letter, placing some sort of marker character before or after them so you can convert them back to uppercase before passing to mcrypt_decrypt.

For example, you could make 97Ahff4DYAH9fh9f into 97_ahff4_d_y_a_h9fh9f. Converting between the two forms should be relatively easing using regular expressions.

Brad Mace
  • 27,194
  • 17
  • 102
  • 148
-1

You could just lower-case it yourself. Use strtolower.

Morten Kristensen
  • 7,412
  • 4
  • 32
  • 52
  • But when it comes to decrypt, the data is broken as it was encrypted using upper and lower case. – Kit Mar 14 '11 at 11:47
  • @Christopher: you understand the data will be broken but still want to do that. Huh?! o_O – zerkms Mar 14 '11 at 11:49
  • @zerkms - no. I want to know if there is a way for mcrypt to only use lowercase chars in the output. – Kit Mar 14 '11 at 11:51
  • @Christopher: oh, ok, get it now. Out of curiousity: why? – zerkms Mar 14 '11 at 11:52
  • @Christopher: I don't get why you even want it lower-cased? You've already "safely" base64-encoded it, so you can just send it over the wire with no troubles. – Morten Kristensen Mar 14 '11 at 11:53
  • @zerkms - Sure, its for a reply to email app that sends a unique string out as the reply email address such as 97Ahff4DYAH9fh9f@mysite.com. Gmail and Outlook reply using the same address, but Hotmail converts the reply email all to lowercase which then errors when I try and decrypt it. – Kit Mar 14 '11 at 11:54
  • @ netrom - please see the edit for the specific reason for this question. – Kit Mar 14 '11 at 11:58