# SHA-256 hash as character string:
sha256("hello world!")
# SHA-256 hash as raw vector:
sha256("hello world!", convert = FALSE)
# Obtain HMAC:
sha256("hello world!", "SECRET_KEY")
# Hashing a file:
tempfile <- tempfile()
cat(rep(letters, 256), file = tempfile)
con <- file(tempfile, open = "rb")
vec <- NULL
while (length(upd <- readBin(con, raw(), 8192))) vec <- c(vec, upd)
sha256(vec)
close(con)
unlink(tempfile)
# SHA-224 hash:
sha224("hello world!")
# SHA-384 hash:
sha384("hello world!")
# SHA-512 hash:
sha512("hello world!")
Run the code above in your browser using DataLab