What is di开发者_运维技巧fference 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
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 encryption key is saved at config/config.php as
$config['encryption_key'] = 'some key';
精彩评论