PHP加密和解密,而不是base64编码


PHP encrypt - and decrypt otherthan base64 encode

在我们的一个web应用程序(PHP, MySQL)中,我们将用户的手机号码保存为加密值,并在我们向他们发送短信时解密它。这个应用程序运行得很好。但

现在GoDaddy删除了base64_encode和decode选项。这样我们就不能给用户发短信了。因此,我们将手机号码恢复到其在本地运行的正常状态。

我的问题是使用密钥加密和解密字符串的最简单和安全的方法是什么

之类的
Normal string : 9876543210  -> After encrypt with a key -> AASASOOPFPOEROP45664654456
Encrypted string : AASASOOPFPOEROP45664654456 -> on decrypt -> 9876543210 

当前代码

function encodeString($str){
  for($i=0; $i<5;$i++)
  {
    $str=strrev(base64_encode($str)); //apply base64 first and then reverse the string
  }
  return $str;
}

function decodeString($str){
 for($i=0; $i<5;$i++)
 {
    $str=base64_decode(strrev($str)); //apply base64 first and then reverse the string}
 }
 return $str;
}

请帮帮我。提前感谢

如果你使用base64编码/解码,你没有加密数据,只是混淆。

我不知道godaddy启用了什么php扩展,所以我建议使用phpSecLib

http://phpseclib.sourceforge.net/

它是一个独立的实现,您可以将其包含在脚本中,并将提供实际的数据加密。AES或Rijndael应该为您的应用程序找到工作

基本上它会用密钥加密字符串,即使您的数据库被破坏,如果没有加密的密钥(您将硬编码到脚本中),数据也无法解密。这与简单地对它进行编码不同,在这种情况下,如果有人掌握了数据库,他们可以通过各种不同的编码方法运行第一个字符串来解码它,直到找到一个有效的方法。然后通过相同的解码方法运行其余的

这里我给你一个简单的例子,我们自己的秘密密钥,你可以使用如下

//使用

加密/解密的秘钥

$key='mysecretkey';//8-32个字符,不含空格

//要加密的字符串

$string1='your sample key, that is the question'; 

//加密字符串

$string2=convert($string1,$key); 

//解密返回

$string3=convert($string2,$key);

//测试输出

  echo '<span style="font-family:Courier">'; 
    echo 'Key: '.$key.'<br>'."'n"; 
    echo $string1.'<br>'."'n"; 
    echo $string2.'<br>'."'n"; 
    echo $string3.'<br>'."'n"; 
    echo '</span>'."'n"; 

Key: mysecretkey
your sample key, that is the question
tvfw#ady{i|-rv|/2q|jq9dj3qkw%e~`jyp|k
your sample key, that is the question

让我知道我可以帮助你更多。