PHP:最安全(可解密)的加密方式? [英] PHP: Most secure (decryptable) encryption method?

查看:368
本文介绍了PHP:最安全(可解密)的加密方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PHP中,哪个(可解密)加密算法是最安全的?

我的意思是MD5无法解密?

I已经找到了具有mcrypt的完整工作类(然后再次使用base64编码),可以加密和解密回来

In PHP, which (decryptable) encryption algorithm is most secure one?
I mean MD5 can't be decrypted back right?
I've found full working class with mcrypt (then encoded with base64 again) which can encrypt and decrypt back.

示例mcrypt加密):

Sample mcrypt (Encrypt):

function encrypt($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->key, $text, MCRYPT_MODE_ECB, $iv);
    return trim($this->safe_b64encode($crypttext));
}

然后用base64重新编码:

Then encode again with base64:

function safe_b64encode($string) {
    $data = base64_encode($string);
    $data = str_replace(array('+','/','='),array('-','_',''),$data);
    return $data;
}

(对不起,代码只是加密,没有解密,我只是给
但是我只想知道是否还有其他更安全的算法,然后使用mcrypt。

(Sorry for the code just with the encrypt, without decrypt. I just giving sample.) But I just want to know if there other more secure algorithm then using mcrypt.

推荐答案

你可能想要MCRYPT_RIJNDAEL_256。具有128,192和256位的块的Rijndael是AES的一般化,它仅支持128位的块大小。

You probably want MCRYPT_RIJNDAEL_256. Rijndael with blocksizes of 128, 192 and 256 bit is a generalization of AES which only supports a blocksize of 128 bit.

请参见: http://us.php.net/manual/en/mcrypt.ciphers.php http://us.php.net/manual/en/book.mcrypt.php

这篇关于PHP:最安全(可解密)的加密方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆