How to Use SHA-256 Hash in Google Sheets
How to Use SHA-256 Hash in Google Sheets
If your reading this blog, chances are you’re curious about how to SHA-256 some data in Google Sheets?
It might sound all fancy, but it’s nothing more than a clever way to turn a bit of text or numbers into a unique string of characters – proper handy if you’re working with passwords or secure data, or Google Ads Offline Conversion Tracking.
Now, if you’r struggling, don’t worry – I’ll take you through it nice ‘n steady.
Whether you’re a spreadsheet whizz or just having a dabble, by the end of this, you’ll be hashing away like there’s no tomorrow. Let’s crack on, shall we?
Here’s how you can do it:
Steps to Create a Custom SHA-256 Function in Google Sheets
To compute a SHA-256 hash in Google Sheets, you can't use a built-in function, but you can create a custom function using Google Apps Script.
- Open Google Sheets:
- Open the Google Sheets where you want to use the SHA-256 function.
- Open the Script Editor:
- Click on
Extensions
in the top menu. - Then select
Apps Script
.
- Click on
- Write the SHA-256 Function:
- Delete the default function in the script editor, and replace it with the following code:
function sha256(data) {
const hash = Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_256, data);
return hash.map(function(byte) {
return ('0' + (byte & 0xFF).toString(16)).slice(-2);
}).join('');
}
- Save the Script:
- Click the disk icon (or press
Ctrl + S
) to save. - You can name your project if prompted (e.g., "SHA256 Function").
- Click the disk icon (or press
- Use the Function in Your Google Sheet:
- Go back to your Google Sheets.Now, you can use the custom
sha256
function in your sheet like a regular function.
=sha256(A1)
WhereA1
is the cell containing the data you want to hash. - Go back to your Google Sheets.Now, you can use the custom
This will return the SHA-256 hash of the data in the specified cell.
Good luck!
Categories:
General |