Mcrypt 输出 - 仅小写?
使用 Mcrypt 时是否可以指定仅小写的输出?
这是我用于加密的代码示例:
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));
}
这样做的原因是我需要一个仅小写的加密字符串。
谢谢你,
克里斯。
编辑
我正在通过电子邮件应用程序创建回复,该应用程序允许用户通过通知电子邮件回复主题。我使用唯一的加密字符串作为回复电子邮件来识别它。 Mcrypt 输出大写和小写字符串。这对于 Gmail 和 Outlook 来说效果很好,但 Hotmail 会将回复地址字符串转换为小写,然后在解密时出错。因此,我需要上面函数的输出字符串仅是小写。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法让
mcrypt_encrypt
提供所有小写输出,但您可以避免在发送的电子邮件地址中使用大写字母。要么找到 mcrypt 输出中尚未使用的 26 个其他字符(可能找不到那么多)来替换大写字母,要么只是小写每个字母,在它们之前或之后放置某种标记字符,以便您可以转换在传递给 mcrypt_decrypt 之前将它们恢复为大写。例如,您可以将
97Ahff4DYAH9fh9f
转换为97_ahff4_d_y_a_h9fh9f
。使用正则表达式在两种形式之间进行转换应该相对容易。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 tomcrypt_decrypt
.For example, you could make
97Ahff4DYAH9fh9f
into97_ahff4_d_y_a_h9fh9f
. Converting between the two forms should be relatively easing using regular expressions.你可以自己小写。使用
strtolower
。You could just lower-case it yourself. Use
strtolower
.