You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'll preface this by saying that shasum has been very useful for me, so thank you for creating it in Stata.
This isn't an issue, but a feature request. It would be useful, at times, to be able to hash a single string. There are easy workarounds, such as generating a single variable in a new frame and hashing it, but it would be convenient to do it in a single command. For example, something like:
shasum, string("xxx") md5
which then returns "f561aaf6ef0bf14d4208bb46a4ccb3ad" in r(string).
You could also put in an option for all the hashes:
shasum, string("xxx") all
which returns r(md5), r(sha1), etc. with each of the different hashes.
The text was updated successfully, but these errors were encountered:
@miserton There's some workarounds in Stata 16+ that are easier than coding this up in C (which I might get to at some point but it's not very high in my TODO list, unfortunately). So here's two options I can give you that were fairly quick for me to add:
Using python (I added the pyhash function to interface with Python's hashlib):
pyhash, hash(md5 sha1 sha256) string(the quick brown fox jumps over the lazy dog)
return list
Using frames:
capture program drop hashstring
program hashstring, rclass
version 16
syntax anything, string(str asis)
local okhashes md5 sha1 sha224 sha256 sha384 sha512
foreach hash of local anything {
if!`:list hash in okhashes' {
disp `"unknown hash '`hash''; allowed: `okhashes'"'
exit 198
}
}
tempname frame
frame create `frame'
frame `frame' {
qui set obs 1
* mata st_addvar("str" + strofreal(strlen(st_local("string"))), "string")
mata st_addvar("strL", "string")
mata st_sstore(1, "string", st_local("string"))
local genhash
foreach hash of local anything {
local genhash `genhash' `hash'(`hash')
}
shasum string, `genhash'
foreach hash of local anything {
local `hash' = `hash'
return local `hash': copy local `hash'
}
}
frame drop `frame'
end
hashstring md5 sha1 sha256, string(the quick brown fox jumps over the lazy dog)
return list
I'll preface this by saying that shasum has been very useful for me, so thank you for creating it in Stata.
This isn't an issue, but a feature request. It would be useful, at times, to be able to hash a single string. There are easy workarounds, such as generating a single variable in a new frame and hashing it, but it would be convenient to do it in a single command. For example, something like:
shasum, string("xxx") md5
which then returns "f561aaf6ef0bf14d4208bb46a4ccb3ad" in r(string).
You could also put in an option for all the hashes:
shasum, string("xxx") all
which returns r(md5), r(sha1), etc. with each of the different hashes.
The text was updated successfully, but these errors were encountered: