Skip to content

Instantly share code, notes, and snippets.

@nyancodeid
Last active August 7, 2024 14:09
Show Gist options
  • Save nyancodeid/e18acf94bfb74991472954dff5cce3b8 to your computer and use it in GitHub Desktop.
Save nyancodeid/e18acf94bfb74991472954dff5cce3b8 to your computer and use it in GitHub Desktop.
Google Apps Script SHA 1
function hmac_sha() {
var text = "I am SHA";
var key = "hello";
var hmacObject = Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_1, text, key);
var txtHash = "";
for (i = 0; i < hmacObject.length; i++) {
var hashVal = hmacObject[i];
if (hashVal < 0) {
hashVal += 256;
}
if (hashVal.toString(16).length == 1) {
txtHash += '0';
}
txtHash += hashVal.toString(16);
}
Logger.log(txtHash);
}
function toSHA1() {
var text = "I am SHA Text or Something";
var rawHash = Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_1, text);
var txtHash = "";
for (i = 0; i < rawHash.length; i++) {
var hashVal = rawHash[i];
if (hashVal < 0) {
hashVal += 256;
}
if (hashVal.toString(16).length == 1) {
txtHash += '0';
}
txtHash += hashVal.toString(16);
}
return txtHash;
}
@rohanchutke
Copy link

do you decryption techniques for sha?

@woprandi
Copy link

woprandi commented Aug 7, 2024

Better : Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_1, input, Utilities.Charset.UTF_8);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment