Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Calculate SHA256 hash for file stream in a Native code(CPP)

1,158 views
Skip to first unread message

Vikas Pushkar

unread,
Jul 8, 2016, 2:35:18 AM7/8/16
to
I am fairly new to managed/unmanaged code here on msdn.

I have a cpp dll where i am trying to calculate sha256 hash on a filestream. i am using System::Security::Cryptography::SHA256::Create(); to create object and all.
i want to pass the name of the file as char * and get the hash in char *.
following is the code:
char * bhai(char *file){

if(file == NULL)
return NULL;
System::String^ aa=gcnew System::String((const char *)file);
System::IO::FileInfo info(aa);
System::IO::FileStream^ fstream = info.Open( System::IO::FileMode::Open );
array<unsigned char>^hash;
System::Security::Cryptography::SHA256^ sha=System::Security::Cryptography::SHA256::Create();
hash= sha->ComputeHash(fstream);
pin_ptr<unsigned char>buff = &hash[0];
char *ret=(char*)malloc(strlen((char*)buff));
fstream->Clos
return ret;
}

but it throws so many errors like mamanged code cannot be called from unmamanged code. i understand the SHA api are managed code but how can i call it from my code?

Thanks
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
0 new messages