4

How can i Convert my password 'String' to Base64 encode of MD5 'String'. Like this string 'password' to 'X03MO1qnZdYdgyfeuILPmQ=='.

Please help me here

OR just let me know the technique that how can i convert this 'password' to 'X03MO1qnZdYdgyfeuILPmQ=='. i will code it myself

Zaid Iqbal
  • 1,662
  • 5
  • 25
  • 45
  • in this case btoa('password') = "cGFzc3dvcmQ=" . i need an output of "X03MO1qnZdYdgyfeuILPmQ==" – Zaid Iqbal Nov 15 '15 at 12:48
  • Take a look to [this](http://stackoverflow.com/questions/9417105/javascript-base-64-decoding-binary-data-doesnt-work) – lrnzcig Nov 15 '15 at 13:53
  • Did I understand well, You want encode string **password** using MD5 and then that result to Base64? – nelek Nov 15 '15 at 17:17
  • yes you are right. i tried but my answer is different than 'X03MO1qnZdYdgyfeuILPmQ==' – Zaid Iqbal Nov 15 '15 at 17:19
  • @ZaidIqbal I posted answer so, try it. – nelek Nov 15 '15 at 17:25
  • If you're encoding "password" and obtaining a fixed, known string, you're doing a **bad** job, if your job is to store passwords securely. – Damien_The_Unbeliever Nov 15 '15 at 17:33
  • Storing passwords with MD5 is utterly unsafe, especially without a salt. You should switch to a slow hash function with a cost factor, like BCrypt or PBKDF2, please have a look at this [answer](http://stackoverflow.com/a/14475388/575765); – martinstoeckli Nov 15 '15 at 20:21

1 Answers1

8

Ok, there is example (vb.net, I'll try to convert in c# using some online converter) :

Dim pwd As String = "password"
Dim hs As System.Security.Cryptography.MD5 = System.Security.Cryptography.MD5.Create
Dim db As Byte() = hs.ComputeHash(System.Text.Encoding.UTF8.GetBytes(pwd))
Dim result As String = Convert.ToBase64String(db)

string password will result with X03MO1qnZdYdgyfeuILPmQ==

Update : converted to c# using online converter (I hope it's correctly converted)

string pwd = "password";
System.Security.Cryptography.MD5 hs = System.Security.Cryptography.MD5.Create;
byte[] db = hs.ComputeHash(System.Text.Encoding.UTF8.GetBytes(pwd));
string result = Convert.ToBase64String(db);
nelek
  • 4,074
  • 3
  • 22
  • 35