PHP sha1_file() ফাংশন
উদাহরণ
টেক্সট ফাইল "test.txt"-এর SHA-1 হ্যাশ গণনা করা হল:
<?php $filename = "test.txt"; $sha1file = sha1_file($filename); echo $sha1file; ?>
The output of the above code:
aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d
সংজ্ঞা ও ব্যবহার
sha1_file() ফাংশন ফাইলের SHA-1 হ্যাশ গণনা করে
sha1_file() ফাংশন মার্কিন সিকিউর হ্যাশ অ্যালগরিদম 1-এর ব্যবহার করে
RFC 3174-এর ব্যাখ্যা - মার্কিন সিকিউর হ্যাশ অ্যালগরিদম 1: SHA-1 একটি ১৬০ বিট আউটপুট নামে "মেসেজ সামগ্রী" তৈরি করে। মেসেজ সামগ্রীটি একটি সংজ্ঞান বা স্বাক্ষর সাবসিগ্নেচার করা যেতে পারে। মেসেজ সামগ্রীকে স্বাক্ষর করা, না মেসেজকে স্বাক্ষর করা, এটা প্রক্রিয়ার দ্রততা বাড়াতে পারে কারণ মেসেজ সামগ্রীর মাপ মেসেজের তুলনায় সাধারণত অনেক ছোট। ডিজিটাল স্বাক্ষরের প্রমাণকারীকে ডিজিটাল স্বাক্ষর তৈরি করার মতোই একই হ্যাশ অ্যালগরিদম ব্যবহার করতে হবে。
Returns the calculated SHA-1 hash if successful, or FALSE if failed.
Syntax
sha1_file(file,raw)
Parameter | Description |
---|---|
file | Required. Specifies the file to be calculated. |
raw |
Optional. Boolean value, specifies the hexadecimal or binary output format:
|
Technical Details
Return Value: | Returns the calculated SHA-1 hash if successful, or FALSE if failed. |
PHP Version: | 4.3.0+ |
Update Log: |
In PHP 5.0,raw Parameters become optional. Since PHP 5.1, sha1_file() can be used by encapsulation. For example: sha1_file("http://codew3c.com/..") |
More Examples
Example 1
Store the SHA-1 hash of "test.txt" in the file:
<?php $sha1file = sha1_file("test.txt"); file_put_contents("sha1file.txt",$sha1file); ?>
Test if "test.txt" has been modified (i.e., SHA-1 has been modified):
<?php $sha1file = file_get_contents("sha1file.txt"); if (sha1_file("test.txt") == $sha1file) { echo "The file is ok."; } else { echo "The file has been changed."; } ?>
The output of the above code:
The file is ok.