Validating extra letter in encrypted text in php
<p>Here is the method i am using encrypt and decrypt in php.</p>

<pre><code>function ecrypt($str){
     $key = "ABCDEH";
     for($i=0; $i&lt;strlen($str); $i++) {
          $char = substr($str, $i, 1);
          $keychar = substr($key, ($i % strlen($key))-1, 1);
          $char = chr(ord($char)+ord($keychar));
          $result.=$char;
       }
    return base64_encode($result);
 }



 function decrypt($str){
    $str = base64_decode($str);
    $result = '';
    $key = "ABCDEH";
  for($i=0; $i&lt;strlen($str); $i++) {
     $char = substr($str, $i, 1);
     $keychar = substr($key, ($i % strlen($key))-1, 1);
     $char = chr(ord($char)-ord($keychar));
     $result.=$char;
  }
 return $result;
</code></pre>

<p>}</p>

<p>The encrypted text may contain name and expiry date.If my encrypted text is:</p>

<p><code>1yUoaCToqmsqq+4unuFdXWJc4R5hnmL</code></p>

<p>i will decrypt and will calculate the expiry date but the problem is if the user entered <code>1yUoaCToqmsqq+4unuFdXWJc4R5hnmLL</code>(i added extra one letter in end of the encrypted key).</p>

<p>If i decrypt it and check the expiry date, its also working.I should throw the error message in case of extra letters.</p>

<p>Please advice me.</p>
