Skip to content

Instantly share code, notes, and snippets.

@imbaker
Last active August 14, 2018 14:58
Show Gist options
  • Save imbaker/fdeedc01bfdcf9409fc1 to your computer and use it in GitHub Desktop.
Save imbaker/fdeedc01bfdcf9409fc1 to your computer and use it in GitHub Desktop.
Code to encode passwords using the ASP.NET Membership provider method
// http://dotnetfiddle.net/wBqZSX
using System;
using System.Text;
using System.Security.Cryptography;
public class Program
{
public static void Main()
{
Console.WriteLine(EncodePassword("Pa55w0rd", "Gr6NjoLK1t89g4pwjmfC1g=="));
}
public static string EncodePassword(string pass, string salt)
{
byte[] bytes = Encoding.Unicode.GetBytes(pass);
byte[] src = Convert.FromBase64String(salt);
byte[] dst = new byte[src.Length + bytes.Length];
Buffer.BlockCopy(src, 0, dst, 0, src.Length);
Buffer.BlockCopy(bytes, 0, dst, src.Length, bytes.Length);
HashAlgorithm algorithm = HashAlgorithm.Create("SHA1");
byte[] inArray = algorithm.ComputeHash(dst);
return Convert.ToBase64String(inArray);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment