How to calculate password hash in C# for Jira users?


While I’m working on migrating our current issue tracking system to the new Jira instance I needed to manually create new users in Jira’s database. The users are stored in the userbase table, but when you take a look you’ll see that the password is not stored instead there is a column called “PASSWORD_HASH” which contains the password in a hashed form. Since Jira uses the OSUser package from OpenSymphony you can go and look in the code.

The code that Jira uses to create the password hash is the following in Java:


private String createHash(String original) {
   byte[] digested = PasswordDigester.digest(original.getBytes());
   byte[] encoded = Base64.encode(digested);

   return new String(encoded);
}

Now here you a digest being generated from the original value. Well this is a SHA-1/512 hash which is then converted to a Base64 representation and that’s all!

Okay here is how you can do this in C#:


using System;
using System.Text;
using System.Security.Cryptography;

public sealed class JiraPasswordHasher
{

    public static string createHash(string original)
    {
        SHA512 shaM = new SHA512Managed();
        var result = shaM.ComputeHash(System.Text.Encoding.ASCII.GetBytes(original));

        return Convert.ToBase64String(result);

    }
}

Have fun!

, , , , , , , , , ,

  • seether

    thank you so much , very helpful ;)