SHA256 HASH function

kusk0r

New Member
Joined
May 17, 2010
Messages
2
Hi, I am looking for a function to hash sensitive data of a collum. After some searching I have found a class module that is supposed to work and imported it. I can't seem to be able to write a working module to call the function from the class module. I got the class module from http://www.frez.co.uk/ ( http://www.frez.co.uk/SHA.zip).

I would appreciate any help with this.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Well it took an hour to find the module, it took two days to realise it had to be imported as a class module and then 6 more hours to make a module to make it work.

Code:
Public Function SHA256(sMessage As String)
     
    Dim clsX As CSHA256
    Set clsX = New CSHA256
     
    SHA256 = clsX.SHA256(sMessage)
     
    Set clsX = Nothing
     
End Function

This seems to work fine for me anyway. Feel free to comment.
 
Upvote 0
End Function[/CODE]This seems to work fine for me anyway. Feel free to comment.
I know this is an old thread, but I'm trying something similar to this original poster. I find that I am able to import the class just fine into Excel 2007, but when I try to use the function, it seems that it always gives me #Ref! no matter what I feed it. If I pass a cell reference as in =SHA256(A1) or directly a string as =SHA256("wordsgohere") it gives #Ref!. Am I not using the function correctly?
 
Upvote 0
I need to Generate SHA256 Hash in excel file is its possible like


In Column A ill enter the text string what i needed and
In Column B it should auto convert to Sha256 code


Awaiting for your help
 
Upvote 0
I need to Generate SHA256 Hash in excel file is its possible like


In Column A ill enter the text string what i needed and
In Column B it should auto convert to Sha256 code


Awaiting for your help

That's kind of what kusk0r's solution does, but I haven't been able to make it work as described, so it would be nice if someone who has successfully done this can chime in.

OG
 
Upvote 0
That's kind of what kusk0r's solution does, but I haven't been able to make it work as described, so it would be nice if someone who has successfully done this can chime in.

OG

I think the problem is that 2007 takes SHA256 as a cell reference rather than a function. So, I tried to rename the function to something else, but when I do that, it doesn't seem to find it. Instead of getting "#REF!" I get "#NAME!" so it's not recognizing the function even though it appears to have been successfully imported as a class.
 
Upvote 0
Here's the trick. The function snippet produces #REF because it uses the same name as the public function within the class. Change the name to mySHA256 or something to avoid contention.

Also, I had to "Insert a Module" and paste the function there. You can't just add it to the workbook.

After those two things, it worked like a charm.
 
Upvote 0
Pls can u share the excel sheet if possible

Thanks in advance

Here's the trick. The function snippet produces #REF because it uses the same name as the public function within the class. Change the name to mySHA256 or something to avoid contention.

Also, I had to "Insert a Module" and paste the function there. You can't just add it to the workbook.

After those two things, it worked like a charm.
 
Upvote 0
How I got it to work in 2007

Here's the trick. The function snippet produces #REF because it uses the same name as the public function within the class. Change the name to mySHA256 or something to avoid contention.

Also, I had to "Insert a Module" and paste the function there. You can't just add it to the workbook.

After those two things, it worked like a charm.

As I mentioned in post #6, I'd already tried renaming the function, once I'd identified it as a problem in 2007. But then I wasn't getting the #Ref! but a #Name!. I'm not sure I mentioned it, but I was importing it as a class module. Finally, what I did to put it all together and get it working for me was...

1) Download the file that kusk0r mentions in the first post of the thread.
2) Edit line 563 and 637 of the file CSHA256.CLS that is included in the ZIP so that the function SHA256 is renamed. I renamed it to SHADD256 for some reason. Save the file.
3) In Excel 2007, go to Developer Tab, Click on Visual Basic.
4) In the IDE, do File|Import File. Locate your CSHA256.CLS file and load it. It will load as a class module.
5) You will need something that actually makes it work, though, and that's the part that kusk0r posted. Right-click in the Project area of the Visual Basic IDE. Choose Insert|Module. It will create a module named Module1 which shows up in the tree. Open it. Paste kusk0r's code from his post earlier, but edit it to reflect the new, longer function that you've renamed so as to avoid Excel 2007+ thinking it's a cell reference. So, in my case, I made it:

Code:
Public Function SHADD256(sMessage As String)
     
    Dim clsX As CSHA256
    Set clsX = New CSHA256
     
    SHADD256 = clsX.SHADD256(sMessage)
     
    Set clsX = Nothing
     
End Function
That should do it. Now, for example, back on your spreadsheet use the function in cell A1 =SHADD256(B1) and in the cell B1, enter the text to be hashed. It all works!

I will not post my spreadsheet, as the original code is copyright Phil Fresle, and he hasn't any distribution licensing in there, but I'd be willing to help folks who need it.
 
Upvote 0
Re: How I got it to work in 2007

Wowwwwwwwwwwwwwww
its really working like a charm :ROFLMAO:
thank you thank you very much...... OswaldGlinkmeyer

:coffee:

As I mentioned in post #6, I'd already tried renaming the function, once I'd identified it as a problem in 2007. But then I wasn't getting the #Ref! but a #Name!. I'm not sure I mentioned it, but I was importing it as a class module. Finally, what I did to put it all together and get it working for me was...

1) Download the file that kusk0r mentions in the first post of the thread.
2) Edit line 563 and 637 of the file CSHA256.CLS that is included in the ZIP so that the function SHA256 is renamed. I renamed it to SHADD256 for some reason. Save the file.
3) In Excel 2007, go to Developer Tab, Click on Visual Basic.
4) In the IDE, do File|Import File. Locate your CSHA256.CLS file and load it. It will load as a class module.
5) You will need something that actually makes it work, though, and that's the part that kusk0r posted. Right-click in the Project area of the Visual Basic IDE. Choose Insert|Module. It will create a module named Module1 which shows up in the tree. Open it. Paste kusk0r's code from his post earlier, but edit it to reflect the new, longer function that you've renamed so as to avoid Excel 2007+ thinking it's a cell reference. So, in my case, I made it:

Code:
Public Function SHADD256(sMessage As String)
     
    Dim clsX As CSHA256
    Set clsX = New CSHA256
     
    SHADD256 = clsX.SHADD256(sMessage)
     
    Set clsX = Nothing
     
End Function
That should do it. Now, for example, back on your spreadsheet use the function in cell A1 =SHADD256(B1) and in the cell B1, enter the text to be hashed. It all works!

I will not post my spreadsheet, as the original code is copyright Phil Fresle, and he hasn't any distribution licensing in there, but I'd be willing to help folks who need it.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,267
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top