Neueste Web-Entwicklung Tutorials
 

PHP sha1_file() Function

<PHP String Referenz

Beispiel

Berechne den SHA-1 - Hash der Textdatei "test.txt" :

<?php
$filename = "test.txt";
$sha1file = sha1_file($filename);
echo $sha1file;
?>

Der Ausgang des Code oben wird sein:

aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d


Definition und Verwendung

Die sha1_file() Funktion berechnet die SHA-1 - Hash einer Datei.

Die sha1_file() Funktion verwendet die US Secure Hash Algorithm 1.

Von RFC 3174 - der US Secure Hash Algorithm 1: "SHA-1 produces a 160-bit output called a message digest. The message digest can then, for example, be input to a signature algorithm which generates or verifies the signature for the message. Signing the message digest rather than the message often improves the efficiency of the process because the message digest is usually much smaller in size than the message. The same hash algorithm must be used by the verifier of a digital signature as was used by the creator of the digital signature." - "SHA-1 produces a 160-bit output called a message digest. The message digest can then, for example, be input to a signature algorithm which generates or verifies the signature for the message. Signing the message digest rather than the message often improves the efficiency of the process because the message digest is usually much smaller in size than the message. The same hash algorithm must be used by the verifier of a digital signature as was used by the creator of the digital signature." - "SHA-1 produces a 160-bit output called a message digest. The message digest can then, for example, be input to a signature algorithm which generates or verifies the signature for the message. Signing the message digest rather than the message often improves the efficiency of the process because the message digest is usually much smaller in size than the message. The same hash algorithm must be used by the verifier of a digital signature as was used by the creator of the digital signature." die "SHA-1 produces a 160-bit output called a message digest. The message digest can then, for example, be input to a signature algorithm which generates or verifies the signature for the message. Signing the message digest rather than the message often improves the efficiency of the process because the message digest is usually much smaller in size than the message. The same hash algorithm must be used by the verifier of a digital signature as was used by the creator of the digital signature." - "SHA-1 produces a 160-bit output called a message digest. The message digest can then, for example, be input to a signature algorithm which generates or verifies the signature for the message. Signing the message digest rather than the message often improves the efficiency of the process because the message digest is usually much smaller in size than the message. The same hash algorithm must be used by the verifier of a digital signature as was used by the creator of the digital signature." , "SHA-1 produces a 160-bit output called a message digest. The message digest can then, for example, be input to a signature algorithm which generates or verifies the signature for the message. Signing the message digest rather than the message often improves the efficiency of the process because the message digest is usually much smaller in size than the message. The same hash algorithm must be used by the verifier of a digital signature as was used by the creator of the digital signature." - "SHA-1 produces a 160-bit output called a message digest. The message digest can then, for example, be input to a signature algorithm which generates or verifies the signature for the message. Signing the message digest rather than the message often improves the efficiency of the process because the message digest is usually much smaller in size than the message. The same hash algorithm must be used by the verifier of a digital signature as was used by the creator of the digital signature." , der "SHA-1 produces a 160-bit output called a message digest. The message digest can then, for example, be input to a signature algorithm which generates or verifies the signature for the message. Signing the message digest rather than the message often improves the efficiency of the process because the message digest is usually much smaller in size than the message. The same hash algorithm must be used by the verifier of a digital signature as was used by the creator of the digital signature." , "SHA-1 produces a 160-bit output called a message digest. The message digest can then, for example, be input to a signature algorithm which generates or verifies the signature for the message. Signing the message digest rather than the message often improves the efficiency of the process because the message digest is usually much smaller in size than the message. The same hash algorithm must be used by the verifier of a digital signature as was used by the creator of the digital signature."

Diese Funktion gibt den berechneten SHA-1-Hash bei Erfolg oder FALSE.


Syntax

sha1_file( file,raw )

Parameter Beschreibung
file Erforderlich. Die Datei berechnet werden
raw Optional. Ein Boolescher Wert, hex oder binäres Ausgabeformat angibt:
  • TRUE - Raw 20 Zeichen Binärformat
  • FALSCH - Standard. 40 Zeichen Hexadezimalzahl

Technische Details

Rückgabewert: Gibt den berechneten SHA-1-Hash bei Erfolg oder FALSE bei einem Fehler
PHP Version: 4.3.0+
Änderungsprotokoll: Der rohe Parameter wurde optional in PHP 5.0

Ab PHP 5.1 ist es möglich , verwenden sha1_file() mit Wrapper, zB sha1_file("http://w3ii.com/..")

Mehr Beispiele

Beispiel 1

Lagern Sie den SHA-1 - Hash "test.txt" in einer Datei:

<?php
$sha1file = sha1_file("test.txt");
file_put_contents("sha1file.txt",$sha1file);
?>

Test , ob "test.txt" geändert worden ist (dh , wenn der SHA-1 Hash wurde geändert):

<?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.";
  }
?>

Der Ausgang des obigen Code könnten sein:

The file is ok.


<PHP String Referenz