Skip to content

Instantly share code, notes, and snippets.

@jolle-c
Last active March 13, 2019 05:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jolle-c/57042bca2e765b0d3b03d39ecc932f74 to your computer and use it in GitHub Desktop.
Save jolle-c/57042bca2e765b0d3b03d39ecc932f74 to your computer and use it in GitHub Desktop.
Returns a hashed string using SHA512 for hashing
[
/**!----------------------------------------------------------------------------
hash_sha512.lasso
Author: Jolle Carlestam
License: Public Domain
Description:
For when you want a hashed string using SHA512 for hashing.
Requires the Lasso 9 version of shell
Sample Usage:
local(content = 'Swedish Räksmörgås a treat for /me/?', key = 'POTIPER)€#/93498374')
hash_sha512(#content, #key)
-> XOrbH6DfHoHXNSjWBQSdb4HRME4WCYA44KQ5WmPpA8KQ+kalMy7trjb8QbzTPBek Wc/UkVaNQJosmTy1BUrcwQ==
Version history
2019-03-13 JC Published to gist
----------------------------------------------------------------------------*/
define hash_sha512(
content::string,
key::string
) => {
local(
_content = string(#content),
hash
)
if(cipher_list(-digest) >> 'SHA512') => {
#hash = encrypt_hmac(
-token = #content,
-password = #key,
-digest = 'SHA512',
-base64
)
else
#_content->replace('"', '')
// using sys_process via shell, calling openssl
local(syntax = 'echo -n "' + #_content + '" | openssl dgst -binary -sha512 -hmac "' + #key + '" | openssl base64 -a')
protect => {
handle_error => {
stdoutnl('error in hash_sha512 shell call ' + error_msg)
}
#hash = string(shell(#syntax))->trim&
}
}
return #hash
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment