12345678910111213141516171819
#include <msclr\auto_handle.h> int main( array< System::String^ >^ args ) { System::String^ str = "hello world!" ; typedef msclr::auto_handle< array<unsigned char> > disposable ; disposable bytes = System::Text::Encoding::UTF8->GetBytes(str) ; using System::Security::Cryptography::SHA1 ; msclr::auto_handle<SHA1> sha1_algorithm = SHA1::Create() ; disposable hash = sha1_algorithm->ComputeHash( bytes.get() ) ; const auto hash_bytes = hash.get() ; for( int i = 0 ; i < hash->Length ; ++i ) System::Console::Write( hash_bytes[i].ToString("x2") ) ; System::Console::WriteLine() ; System::Console::ReadLine() ; }