EldoS | Feel safer!

Software components for data protection, secure storage and transfer

SBHashFunction Issue with ASP.NET VB

Also by EldoS: Solid File System
A virtual file system that offers a feature-rich storage for application documents and data with built-in compression and encryption.
#8535
Posted: 12/24/2008 04:57:07
by Dan Saul (Standard support level)
Joined: 07/23/2008
Posts: 17

Hi,

I'm using this code to obtain the hash of a PDF to store in a database but the visual Web Developer error message underlines "SBConstants.Unit.SB_ALGORITHM_DGST_SHA1" with the error message:

Value of stype 'Short' cannot be converted to 'SBCryptoProv.TelCustomCryptoProvider'

Please advise. Also, in your opinion, is it best to store the hash as a string or in its original binary form in a database for later comparison?

Thanks.

Code

Private Function GetHash(ByVal path As String) As String

        Dim fs As New FileStream(path, FileMode.Open, FileAccess.Read)
        Dim strHsh As String = ""

        Try
            Dim hash As New TElHashFunction(SBConstants.Unit.SB_ALGORITHM_DGST_SHA1)
            hash.Update(fs, 0)
            strHsh = SBUtils.Unit.BinaryToString(hash.Finish())
        Finally
            fs.Close()
        End Try

        Return strHsh

    End Function
#8537
Posted: 12/24/2008 07:00:42
by Ken Ivanov (EldoS Corp.)

Thank you for contacting us.

The constructor of TElHashFunction expects two parameters on input, a message digest algorithm and a cryptoprovider object. Please use the following code to create the object:

Dim prov As SBCryptoProv.TElCustomCryptoProvider = Nothing
Dim hash As New TElHashFunction(SBConstants.Unit.SB_ALGORITHM_DGST_SHA1, prov)

Quote
Also, in your opinion, is it best to store the hash as a string or in its original binary form in a database for later comparison?

It depends on the specifics of your database and your application (you are free to choose the format that is more suitable for using within your application). From security point of view, there's no difference between storing hash value in either binary or ASCII form.
#8538
Posted: 12/24/2008 09:14:28
by Dan Saul (Standard support level)
Joined: 07/23/2008
Posts: 17

Thank you. Much appreciated.

With regard to the second question about db storage, it's not a matter of security but of verification.

Basically I am storing the original file's hash before timestamping the file and then the hash after timestamping to use as proof of a document's state at a certain point in time. i.e. to prove that no changes have been made to the document since timestamping. I just needed to know whether it was best to store the original binary data or a conversion to string.

Thanks.
#8540
Posted: 12/24/2008 09:33:16
by Ken Ivanov (EldoS Corp.)

Well, in both cases the same value is kept (in different encodings though). Actually, an encoded string requires twice more place than a binary digest value (as each binary byte is replaced with two ASCII characters). If you do not need the values stored in database to be human-readable, storing binary-encoded digests will be a more effective approach.

Merry Christmas and Happy New Year!
#8541
Posted: 12/24/2008 09:53:05
by Dan Saul (Standard support level)
Joined: 07/23/2008
Posts: 17

Thanks, you too!
Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.

Reply

Statistics

Topic viewed 1131 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!