module Digest: Digest
本節中的函式使用 MD5 雜湊函式來產生 128 位元 (16 位元組) 的摘要。MD5 並非密碼學上安全的。因此,這些函式不應用於安全敏感的應用程式。下方的 BLAKE2 函式在密碼學上是安全的。
typet =
string
摘要的類型:16 位元組的字串。
val compare : t -> t -> int
用於 16 位元組摘要的比較函式,其規格與 compare
相同,且實作與 String.compare
共用。連同類型 t
,此函式 compare
允許模組 Digest
作為函子 Set.Make
和 Map.Make
的參數傳遞。
val equal : t -> t -> bool
用於 16 位元組摘要的相等函式。
val string : string -> t
傳回給定字串的摘要。
val bytes : bytes -> t
傳回給定位元組序列的摘要。
val substring : string -> int -> int -> t
Digest.substring s ofs len
會傳回從索引 ofs
開始並包含 len
個字元的 s
子字串的摘要。
val subbytes : bytes -> int -> int -> t
Digest.subbytes s ofs len
會傳回從索引 ofs
開始並包含 len
個位元組的 s
子序列的摘要。
val channel : in_channel -> int -> t
如果 len
為非負數,則 Digest.channel ic len
會從通道 ic
讀取 len
個字元並傳回其摘要,或者如果在讀取 len
個字元之前到達檔案結尾,則會引發 End_of_file
。如果 len
為負數,則 Digest.channel ic len
會從 ic
讀取所有字元直到到達檔案結尾,並傳回其摘要。
val file : string -> t
傳回給定名稱檔案的摘要。
val output : out_channel -> t -> unit
將摘要寫入給定的輸出通道。
val input : in_channel -> t
從給定的輸入通道讀取摘要。
val to_hex : t -> string
傳回給定摘要的可列印十六進位表示法。
Invalid_argument
。val of_hex : string -> t
將十六進位表示法轉換回對應的摘要。
Invalid_argument
。val from_hex : string -> t
與 Digest.of_hex
相同的函式。
module type S =sig
..end
從字元字串、位元組陣列和檔案產生長度為 hash_length
的摘要的雜湊函式簽名。
module BLAKE128:S
BLAKE128
是產生 128 位元(16 位元組)摘要的 BLAKE2b 雜湊函式。
module BLAKE256:S
BLAKE256
是產生 256 位元(32 位元組)摘要的 BLAKE2b 雜湊函式。
module BLAKE512:S
BLAKE512
是產生 512 位元(64 位元組)摘要的 BLAKE2b 雜湊函式。
module MD5:S
MD5
是 MD5 雜湊函式。