Here is my golang, it working
http://stackoverflow.com/questions/41008725/rfc2898derivebytes-vs-golang-pbkdf2/41009043#41009043

On Wed, Dec 7, 2016 at 10:07 AM, tuanhoanganh <hatua...@gmail.com> wrote:

> Here is my C# Rfc2898DeriveBytes
>
> using System;using System.Text;using System.Security.Cryptography;
> public class Program{
>     public static void Main()
>     {
>         byte[] saltBytes = Encoding.Unicode.GetBytes("47687");
>         Console.WriteLine(Convert.ToBase64String(saltBytes));
>
>         byte[] passBytes = Encoding.Unicode.GetBytes("123456");
>         Console.WriteLine(Convert.ToBase64String(passBytes));
>
>         Rfc2898DeriveBytes k1 = new Rfc2898DeriveBytes(passBytes, saltBytes, 
> 1000);
>         byte[] hashbyte = k1.GetBytes(32);
>
>         Console.WriteLine(Convert.ToBase64String(hashbyte));
>     }}
>
> Result is
>
> NAA3ADYAOAA3AA==
>
> MQAyADMANAA1ADYA
>
> aOyDnGG22ebqGmMvY7zQwdT+UKF6hUUmAt2Uc0jj2io=
>
> My golang code is
>
> package main
> import (
>     "crypto/sha1"
>     "fmt"
>     "golang.org/x/crypto/pbkdf2"
>     b64 "encoding/base64")
> var (
>     PasswordSecuritySalt       = "47687"
>     PasswordSecurityIterations = 1000
>     PasswordSecurityKeylen     = 32)
>
> func HashPassword(str string) string {
>     hashedPassword := pbkdf2.Key([]byte(str), []byte(PasswordSecuritySalt), 
> PasswordSecurityIterations, PasswordSecurityKeylen, sha1.New)
>     return  b64.StdEncoding.EncodeToString(hashedPassword)}
>
> func main() {
>     password := "123456"
>     fmt.Println(PasswordSecuritySalt + " " + password)
>     fmt.Println(HashPassword(password))
> }
>
> Result is
>
> 47687 123456
>
> EVqb1dCe8p+iVEquNjJmHhSjruGATNQX73F6msXivM8=
>
> Why golang result hash password is different with C#. Please help me.
>
> Here is my stackoverflow : http://stackoverflow.com/questions/41008725/
> rfc2898derivebytes-vs-golang-pbkdf2
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to