从sha256生成hash看PHP为何是最好的语言?

sha256生成文件的唯一hash

php版本:

$filePath = ""//file path; 
$sha256 = hash_file("sha256", $filePath);

go版本:


package main



import (

  "crypto/sha256"

  "fmt"

  "io"

  "log"

  "os"

)

func main() {

  f, err := os.Open("file.txt")

  if err != nil {

    log.Fatal(err)

  }

  defer f.Close()



  h := sha256.New()

  if _, err := io.Copy(h, f); err != nil {

    log.Fatal(err)

  }



  fmt.Printf("%x", h.Sum(nil))

}

java版本


    byte[] buffer= new byte[8192];

    int count;

    MessageDigest digest = MessageDigest.getInstance("SHA-256");

    BufferedInputStream bis = new BufferedInputStream(new FileInputStream(fileName));

    while ((count = bis.read(buffer)) > 0) {

        digest.update(buffer, 0, count);

    }

    bis.close();

    byte[] hash = digest.digest();

    System.out.println(byte2Hex(hash));

     private static String byte2Hex(byte[] bytes){

            StringBuffer stringBuffer = new StringBuffer();

            String temp = null;

            for (int i=0;i

所以:________________________________________________

从代码量来说,PHP是世界上最好的语言。

你可能感兴趣的:(从sha256生成hash看PHP为何是最好的语言?)