在本页中:
sha1
bytes->hex-string
hex-string->bytes

10 SHA1 Message Digest

 (require file/sha1) package: base

See openssl/sha1 for a faster implementation.

函数

(sha1 in [start end])  string?

  in : (or/c bytes? input-port?)
  start : exact-nonnegative-integer? = 0
  end : (or/c #f exact-nonnegative-integer?) = #f
Returns a 40-character string that represents the SHA-1 hash (in hexadecimal notation) of the content from in. The in, start, and end arguments are treated the same as sha1-bytes from racket/base.

The sha1 function composes bytes->hex-string with sha1-bytes.

例如:
> (sha1 (open-input-bytes #"abc"))

"a9993e364706816aba3e25717850c26c9cd0d89d"

修改于package base的7.0.0.5版本:Allowed a byte string as in and added the start and end arguments.

函数

(sha1-bytes in [start end])  string?

  in : (or/c bytes? input-port?)
  start : exact-nonnegative-integer? = 0
  end : (or/c #f exact-nonnegative-integer?) = #f
The same as sha1-bytes from racket/base, returns a 20-byte byte string that represents the SHA-1 hash of the content from in.

例如:
> (sha1-bytes (open-input-bytes #"abc"))

#"\251\231>6G\6\201j\272>%qxP\302l\234\320\330\235"

修改于package base的7.0.0.5版本:Allowed a byte string as in and added the start and end arguments.

函数

(bytes->hex-string bstr)  string?

  bstr : bytes?
Converts the given byte string to a string representation, where each byte in bstr is converted to its two-digit hexadecimal representation in the resulting string.

例如:
> (bytes->hex-string #"turtles")

"747572746c6573"

函数

(hex-string->bytes str)  bytes?

  str : string?
Converts the given string to a byte string, where each pair of characters in str is converted to a single byte in the result.

例如:
> (hex-string->bytes "70")

#"p"

> (hex-string->bytes "Af")

#"\257"