Neueste Web-Entwicklung Tutorials
 

PHP sha1() Function

<PHP String Referenz

Beispiel

Berechne den SHA-1 - Hash der Zeichenfolge "Hello" :

<?php
$str = "Hello";
echo sha1($str);
?>
Führen Sie zB »

Definition und Verwendung

Die sha1() Funktion berechnet den SHA-1 Hash einer Zeichenfolge.

Die sha1() Funktion verwendet den 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."

Tipp: Um die SHA-1 - Hash einer Datei verwenden , um die Berechnung sha1_file() Funktion.


Syntax

sha1( string,raw )

Parameter Beschreibung
string Erforderlich. Die Zeichenfolge berechnet werden
raw Optional. Geben Sie hex oder Binär-Ausgabeformat:
  • 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

Mehr Beispiele

Beispiel 1

Drucken Sie das Ergebnis von sha1() :

<?php
$str = "Hello";
echo "The string: ".$str."<br>";
echo "TRUE - Raw 20 character binary format: ".sha1($str, TRUE)."<br>";
echo "FALSE - 40 character hex number: ".sha1($str)."<br>";
?>
Führen Sie zB »

Beispiel 2

Drucken Sie das Ergebnis der sha1() und dann testen:

<?php
$str = "Hello";
echo sha1($str);

if (sha1($str) == "f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0")
  {
  echo "<br>Hello world!";
  exit;
  }
?>
Führen Sie zB »

<PHP String Referenz