crypt

3DES 数据加密(3DES/ECB/zeroPadding)PHP <= 7.0.x

久未见 提交于 2019-11-26 12:21:05
1. 3DES 简介   3DES(即Triple DES)是DES向AES过渡的加密算法(1999年,NIST将3-DES指定为过渡的加密标准),加密算法,其具体实现如下:设Ek()和Dk()代表DES算法的加密和解密过程,K代表DES算法使用的密钥,M代表明文,C代表密文,这样: 3DES加密过程为: C = Ek3(Dk2(Ek1(M))) 3DES解密过程为: M = Dk1(EK2(Dk3(C)))   常见的“对称密钥”加密算法主要有DES、3DES(TripleDES)、AES、RC2、RC4、RC5和Blowfish等,具体每个算法的实现我就不再这里说了,感兴趣的自己去查找。 2. 加解密类 Crypt3Des class Crypt3Des { public $key = ""; function __construct($key) { $this->key = $key; } /** * 数据加密 * @param string $input * @return void */ function encrypt($input) { $size = mcrypt_get_block_size(MCRYPT_3DES, 'ecb'); $input = $this->pkcs5_pad($input, $size); // $key = str_pad($this-

Why does crypt/blowfish generate the same hash with two different salts?

寵の児 提交于 2019-11-26 08:08:49
问题 This question has to do with PHP\'s implementation of crypt(). For this question, the first 7 characters of the salt are not counted, so a salt \' $2a$07$a \' would be said to have a length of 1, as it is only 1 character of salt and seven characters of meta-data. When using salt strings longer than 22 characters, there is no change in the hash generated (i.e., truncation), and when using strings shorter than 21 characters the salt will automatically be padded (with \' $ \' characters,