bitwiseshiftleft/sjcl — Issue #37: Porting Help
Author: oliverw
Created: 2011-10-23 18:02:42+00:00
State: open

One question. Is the PKBDF2 implementation of SJCL compatble with .Net's [Rfc2898DeriveBytes class](http://msdn.microsoft.com/en-us/library/system.security.cryptography.rfc2898derivebytes.aspx)?

I'm trying to port implement the equivalent of this C# Code to the SJCL but can't get the javascript implementation to produce matching values:

C# Code:

var Salt2 = "pQ.+!M=+";
var salt = Salt2 + username;
var rfc2898 = new Rfc2898DeriveBytes(password, Encoding.UTF8.GetBytes(salt), Rfc2898Iterations);
return Convert.ToBase64String(rfc2898.GetBytes(32));

Javascript Code:

var Salt2 = "pQ.+!M=+";
var username = "foo";
var password = "bar";

var salt = sjcl.codec.utf8String.toBits(Salt2 + username);
var rfc2898 = sjcl.misc.cachedPbkdf2(password, { salt: salt , iter: Rfc2898Iterations });
var passwordHash = sjcl.codec.base64.fromBits(rfc2898.key);
alert(passwordHash );