The functions sha1,
sha256, sha512, md4,
md5 and ripemd160 bind to the respective digest
functions in OpenSSL’s libcrypto. Both binary and string inputs are
supported and the output type will match the input type.
[1] "acbd18db4cc2f85cedef654fccc4a4d8"
md5 ac:bd:18:db:4c:c2:f8:5c:ed:ef:65:4f:cc:c4:a4:d8
Functions are fully vectorized for the case of character vectors: a vector with n strings will return n hashes.
[1] "acbd18db4cc2f85cedef654fccc4a4d8" "37b51d194a7513e45b56f6524f2d51f2"
[3] "73feffa4b7f6bb68e44cf984c85f6e88"
Besides character and raw vectors we can pass a connection object (e.g. a file, socket or url). In this case the function will stream-hash the binary contents of the connection.
md5 3b:94:d8:c8:17:32:c1:9d:c0:58:0f:1b:dc:ad:ea:fe
Same for URLs. The hash of the R-installer.exe
below should match the one in md5sum.txt
# Stream-hash from a network connection
as.character(md5(url("https://cran.r-project.org/bin/windows/base/old/4.0.0/R-4.0.0-win.exe")))
# Compare
readLines('https://cran.r-project.org/bin/windows/base/old/4.0.0/md5sum.txt')Similar functionality is also available in the digest package, but with a slightly different interface:
Attaching package: 'digest'
The following object is masked from 'package:openssl':
sha1
[1] "acbd18db4cc2f85cedef654fccc4a4d8"
[1] "1e21203371fb923dcbc218897f1af95e"
md5 fa:fc:b3:f6:1e:12:d2:75:6e:f3:6d:b9:38:54:1e:52