최신 웹 개발 튜토리얼
 

PHP sha1() Function

<PHP 문자열 참조

문자열의 SHA-1 해시 계산 "Hello" :

<?php
$str = "Hello";
echo sha1($str);
?>
»실행 예

정의 및 사용

sha1() 함수는 문자열의 SHA-1 해시를 계산한다.

sha1() 함수는 US 보안 해시 알고리즘 1을 사용한다.

RFC 3174에서 - 미국의 보안 해시 알고리즘 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 해시를 계산하려면 sha1_file() 함수를.


통사론

sha1( string,raw )

매개 변수 기술
string 필요합니다. 문자열은 계산한다
raw 선택 과목. 진수 또는 이진 출력 형식을 지정합니다 :
  • TRUE - 원시 20 문자 바이너리 형식
  • FALSE - 기본. 40 문자의 16 진수

기술적 세부 사항

반환 값 : 성공에 계산 된 SHA-1 해시를 반환, 실패하면 FALSE
PHP 버전 : 4.3.0+
변경 내역 : 원시 매개 변수는 PHP 5.0에서 선택되었다

더 예

예 1

결과 인쇄 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>";
?>
»실행 예

예 2

결과 인쇄 sha1() 테스트 다음과 :

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

if (sha1($str) == "f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0")
  {
  echo "<br>Hello world!";
  exit;
  }
?>
»실행 예

<PHP 문자열 참조