简体   繁体   中英

sha1 in CodeIgniter?

What is difference in CodeIgniter sha1 and normal PHP sha1? For example:

$codeigniter_hashed = $this -> encrypt -> sha1( "test" );

And

$normal_hashed = sha1("test");

Both will return same values. Where does CodeIgniter uses encryption_key ?

If your PHP installation doesn't have sha1 installed, you can use the CI version. If your PHP installation already has it, you don't need to use the CI function.

From the user guide:

$this->encrypt->sha1();

SHA1 encoding function. Provide a string and it will return a 160 bit one way hash. Note: SHA1, just like MD5 is non-decodable. Example: $hash = $this->encrypt->sha1('Some string');

Many PHP installations have SHA1 support by default so if all you need is to encode a hash it's simpler to use the native function: $hash = sha1('Some string');

If your server does not support SHA1 you can use the provided function.

More info: http://codeigniter.com/user_guide/libraries/encryption.html

加密密钥保存在config / config.php中

$config['encryption_key'] = 'some key';

Pretty sure the function you show is a pure SHA encrypt - you only use a specific encryption_key if you want to key/encode the data so only you (the holder of the encryption key), will be able to decrypt it.

$encrypted_with_encryption_key = $this->encrypt->encode($var);

$encrypted_with_sha_no_enc_key = $this->encrypt->sha1($var);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM