Click here to Skip to main content
15,881,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have made a website, in which on login I am using pbkdf2_sha256 for password hashing. I have used salt also. I want to make a simple software just for the experience, I want to login into the c# software using same credentials as saved by the website. I have seen Rfc2898DeriveBytes I guess it only takes 2 arguments (password, salt in integer). But what about iterations I have specified on the website?

Anyone, please guide me how to make a login in c# (WPF) application and use pbkdf2_sha256 to create a hash and to verify the password.

I have seen PBKDF2.Net NuGet package and BouncyCastle NuGet Package, but i am not getting how to use them i am getting a lot of error in syntax what ever i have copied from some sites.

i have also used

C#
var salt = "FbSnXHPo12gb";
var password = "geheim";
var interactions = 12000;


using (var hmac = new HMACSHA256())
{
    var df = new Pbkdf2(hmac, password, salt, interactions);
    Console.WriteLine(Convert.ToBase64String(df.GetBytes(32)));
}


please help me

What I have tried:

C#
using System.Security.Cryptography;
using System.Configuration;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Engines;
using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.Crypto.Modes;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Security;

namespace login
{

    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {

        public MainWindow()
        {
            InitializeComponent();
        }

        

        private void test_Click(object sender, RoutedEventArgs e)
        {
            int iterations = 100000; // The number of times to encrypt the password - change this
            int saltByteSize = 64; // the salt size - change this
            int hashByteSize = 128; // the final hash - change this

            BouncyCastleHashing mainHashingLib = new BouncyCastleHashing();

            var password = "password"; // That's really secure! :)

            byte[] saltBytes = mainHashingLib.CreateSalt(saltByteSize);
            string saltString = Convert.ToBase64String(saltBytes);

            string pwdHash = mainHashingLib.PBKDF2_SHA256_GetHash(password, saltString, iterations, hashByteSize);

            var isValid = mainHashingLib.ValidatePassword(password, saltBytes, iterations, hashByteSize, Convert.FromBase64String(pwdHash));
        }
    }
}
Posted
Updated 7-Sep-17 13:43pm

Google Search gods are your friend... This search: BouncyCastle documentation Pbkdf2 c#[^] found this accepted solution: How to create a PBKDF2-SHA256 password hash in C# / Bouncy Castle - Stack Overflow[^]
 
Share this answer
 
Please have a look at those links, they are good alternatives I think and so informative, the second one is a direct link to the class library I used to implement .


https://crackstation.net/hashing-security.htm


https://github.com/defuse/password-hashing/blob/master/PasswordStorage.cs
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900