views:

565

answers:

7

Hi,

Does anyone know if there exist a dll in windows (2003 server) which I can call to calculate a MD5/SHA1 hash for a string?

I've written a .dll in C# that do this but I'm not allowed to use this because of company regulations for our servers.

/Ausgar

+4  A: 

If you do have a .NET 2.0 installed (which I think you do), then yes, there is one.

It's accessible via COM as System.Security.Cryptography.MD5CryptoServiceProvider and System.Security.Cryptography.HMACSHA1, respectively.

It's no use to implent it in C# as C# relies on .NET and .NET has implemented it for you already.

P.S. If there is no .NET on your system or you reluct at using .NET/COM for some reason, then there is sample using Microsoft Crypto API.

Quassnoi
I think the idea is provided Hashing to COM based consumer. Whether these providers can be used may depend on the consumer, e.g, VBScript may struggle to use these providers
AnthonyWJones
What are you saying? That these classes can't be used from VBScript/VB6?
Ausgar
A: 

Hi!

I will look in to this right now! I think they have .Net 2.0 installed...

I'll get back to you!

/Ausgar

Ausgar
A: 

Hi,

I'm having trouble to "import" the correct .dll. You are right that I need to make a com call, since I'm making the call from a crap languge called MyExtra! basic (some sort of VB6 ripoff).

Is this the correct dll: mscorlib.dll?

/Ausgar

Ausgar
If you are making a COM call, you don't need to know the name of the DLL. In plain VB you'd do something like CreateObject("System.Security.Cryptography.MD5CryptoServiceProvider"). If your language supports COM then there should be some kind of similar construction.
Quassnoi
A: 

Have you tried openSSL?

(e.g. there are precompiled libeay32.dll and libssl32.dll files for windows, I'm not sure where the docs are that describe the DLL functions available in each of those, though)

Jason S
A: 

Hi,

OpenSSL is not installed on the servers. Thanks anyway Jason!

/Ausgar

Ausgar
A: 

If you are making a COM call, you don't need to know the name of the DLL. In plain VB you'd do something like CreateObject("System.Security.Cryptography.MD5CryptoServiceProvider"). If your language supports COM then there should be some kind of similar construction. – Quassnoi (yesterday)

Hi,

This is my code where I try to use the MD5CryptoServiceProvider:

    Sub Main

        Dim foo as String
        Dim bar as object        


       set bar =  CreateObject("System.Security.Cryptography.MD5CryptoServiceProvider")

         if bar is Nothing then
            Msgbox "ERROR"
         else
            MsgBox "Got ref!"
        end if


        foo = bar.ComputeHash("12345")
        MsgBox foo

end sub

But I get this error message "No such propery or method". What i'm I missing???

/Ausgar

Ausgar
A: 

Not solved this yet. I guess nobody is instrested in this question anymore and therefor I will give Jan credit for his anwer...

Thanks a lot for the input regarding this question

Ausgar