# Getting a error when trying to add my rep in experimental code column

**URL:** https://community.glideapps.com/t/getting-a-error-when-trying-to-add-my-rep-in-experimental-code-column/65714
**Category:** Ask for Help
**Created:** [September 2, 2023, 1:10pm UTC](https://community.glideapps.com/t/getting-a-error-when-trying-to-add-my-rep-in-experimental-code-column/65714 "2023-09-02T13:10:04Z")
**Posts on this page:** 1
**Showing post:** 42

<div class="post-metadata">

### Author: ![Eric\_Penn](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/eric_penn/32/73888_2.png) [@Eric\_Penn](https://community.glideapps.com/u/Eric_Penn)
#### Post date: [October 8, 2023, 5:27am UTC](https://community.glideapps.com/t/getting-a-error-when-trying-to-add-my-rep-in-experimental-code-column/65714/42 "2023-10-08T05:27:24Z")

</div>

Here you go… put the Input in A2 the Secret Key in B2 and your Output will go in C2.

```auto
function computeHMACSHA1() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  
  // Get the input text from cell A2 and B2
  var inputText = sheet.getRange("A2").getValue();
  var secretKey = sheet.getRange("B2").getValue();
  
  // Convert inputText and secretKey to Base64
  var inputTextBase64 = Utilities.base64Encode(inputText);
  var secretKeyBase64 = Utilities.base64Encode(secretKey);
  
  // Convert Base64 strings back to binary
  var inputBytes = Utilities.base64Decode(inputTextBase64);
  var keyBytes = Utilities.base64Decode(secretKeyBase64);
  
  // Implement HMAC-SHA1 manually
  var blockSize = 64; // HMAC-SHA1 block size
  if (keyBytes.length > blockSize) {
    keyBytes = Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_1, keyBytes);
  }
  
  while (keyBytes.length < blockSize) {
    keyBytes.push(0);
  }
  
  var oKeyPad = [];
  var iKeyPad = [];
  
  for (var i = 0; i < blockSize; i++) {
    oKeyPad.push(keyBytes[i] ^ 0x5C);
    iKeyPad.push(keyBytes[i] ^ 0x36);
  }
  
  var innerHash = Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_1, iKeyPad.concat(inputBytes));
  var finalHash = Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_1, oKeyPad.concat(innerHash));
  
  // Convert the binary hash to a hexadecimal string
  var hmacSha1Hex = '';
  for (var i = 0; i < finalHash.length; i++) {
    var byte = finalHash[i];
    hmacSha1Hex += (byte & 0xFF).toString(16).padStart(2, '0'); // Format as two-digit hex without leading 0's
  }
  
  // Put the result in cell C2
  sheet.getRange("C2").setValue(hmacSha1Hex);
}

```

 ![Screenshot 2023-10-07 at 10.28.42 PM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/3/6/3687d6709a87b6286ead87e9d1e1dc0e4a5b4719.png)  
 ![Screenshot 2023-10-07 at 10.37.27 PM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/3/0/303776cfd34ff89422ee8926aefd2b0cf841d572.png)

---

_[View the full topic](https://community.glideapps.com/t/getting-a-error-when-trying-to-add-my-rep-in-experimental-code-column/65714)._
