Need help with SHA with SALT

Hello, how can i make this in C++ CLI Form, i need to generate Salt from password field. SALT is for example "passwordSalt"

SB_SALT = "passwordSalt"
 
.sha1(sha1(SB_SALT . $pass)).


Thanks.
Last edited on
Normally you add the salt to the password.

String^ SaltedPassword = txtPassword->Text + "passwordSalt"

BTW. sha1 is not secure anymore: https://en.wikipedia.org/wiki/SHA-1
for example password abcde123456 + SALT ("SourceBans") is somethink like this "5991cd0c49ed271d7bd81745bb24988943941a0d" and i need library where i can make sha1 from string, because this web application still using sha1 for password hashing and i need make it same for login system. Thanks.
Try this:
1
2
3
4
5
6
7
8
9
String^ StringToSha1 (String^ password, String^ salt)
    {
      System::Text::Encoding^ encoding = System::Text::Encoding::Default;
      array<Byte>^ bytes = encoding->GetBytes (password + salt);
      System::Security::Cryptography::SHA1CryptoServiceProvider^ sha = gcnew System::Security::Cryptography::SHA1CryptoServiceProvider;
      array<unsigned char>^ hash = sha->ComputeHash (bytes);

      return encoding->GetString (hash);
    }
i've got 3 problems here, how can i fix this?

1. http://prntscr.com/bab13i
2. http://prntscr.com/bab1dp
3. http://prntscr.com/bab1lr

Thanks
I suspect that you use somewhere using namespace std and so the compiler treats the .NET array as std::array.
Try System::array instead
u remove std but still same problem, i try make new include for separate namespaces, but problem still exist :/

http://prntscr.com/bah9qz

http://prntscr.com/baha9v

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#ifndef ADAM_SHA1_INC
#define ADAM_SHA1_INC

//using namespace std;
using namespace System;
using namespace System::Array; //must be part of namespace or something else
using namespace System::Net;
using namespace System::Text;
using namespace System::IO;
using namespace msclr::interop;

String^ StringToSha1(String^ password, String^ salt)
{
	Encoding^ encoding = Encoding::Default;
	array<Byte>^ bytes = encoding->GetBytes(password + salt);
	System::Security::Cryptography::SHA1CryptoServiceProvider^ sha = gcnew System::Security::Cryptography::SHA1CryptoServiceProvider;
	array<unsigned char>^ hash = sha->ComputeHash(bytes);

	return encoding->GetString(hash);
}

#endif // ndef ADAM_SHA1_INC 
You probably have this std namespace in other files.
You can remove this. using namespace System::Array;
i try new project and it works, but for string "8A6634C8" and salt "SourceBans" i get only this http://prntscr.com/baky2h
Looks like an encoding problem.

Try other encodings Encoding^ encoding = Encoding::Default; instead of of the default
no encoding works like i expect. i make solution with php, i make php script which take get argument with password and result is sha1 hash what i need and in C++ i have httpwebrequest where i take response stream and put it into string :) it works
Topic archived. No new replies allowed.