protected override bool CheckSecret(PasswdBase info) { CryExtInfo infos = info.ExtraInfo as CryExtInfo; if (infos == null) { return(false); } using (HMACSHA512 hash512 = new HMACSHA512(infos.Key)) { byte[] pwdDate = Encoding.UTF8.GetBytes(this.Password); byte[] pwdWithSalt = new byte[pwdDate.Length + infos.Salt.Length]; Array.Copy(pwdDate, pwdWithSalt, pwdDate.Length); Array.Copy(infos.Salt, 0, pwdWithSalt, pwdDate.Length, infos.Salt.Length); byte[] pwdBuffer = hash512.ComputeHash(pwdWithSalt); for (int i = 0; i <= infos.Count; i++) { pwdBuffer = hash512.ComputeHash(pwdBuffer); } return(this.SlowCompose(info.Password, pwdBuffer)); } }
protected override PasswdBase Secret() { if (this.date.VersionHash == "") { throw new Exception("the VERSION is not set"); } using (HMACSHA512 hash512 = new HMACSHA512()) { using (RNGCryptoServiceProvider rnd = new RNGCryptoServiceProvider()) { Random cntRnd = new Random(); CryExtInfo extra = new CryExtInfo(); extra.Count = cntRnd.Next(this.MinCount, this.MaxCount); extra.Salt = new byte[64]; //fill the Randomize salt ,the Salt's length is //512bit rnd.GetNonZeroBytes(extra.Salt); using (SHA512CryptoServiceProvider sha512 = new SHA512CryptoServiceProvider()) { byte[] KeyBuffer = new byte[64]; rnd.GetNonZeroBytes(KeyBuffer); KeyBuffer = sha512.ComputeHash(KeyBuffer); extra.Key = KeyBuffer; hash512.Key = KeyBuffer; this.date.ExtraInfo = extra; byte[] pwdBuffer; byte[] pwdDate = Encoding.UTF8.GetBytes(this.Password); //now we add the salt to the string byte[] pwdWithSalt = new byte[pwdDate.Length + extra.Salt.Length]; Array.Copy(pwdDate, pwdWithSalt, pwdDate.Length); Array.Copy(extra.Salt, 0, pwdWithSalt, pwdDate.Length, extra.Salt.Length); pwdBuffer = hash512.ComputeHash(pwdWithSalt); for (int i = 0; i <= extra.Count; i++) { pwdBuffer = hash512.ComputeHash(pwdBuffer); } this.date.Password = pwdBuffer; } } } return(this.date); }
protected override PasswdBase Secret() { if (this.date.VersionHash == "") throw new Exception ("the VERSION is not set"); using (HMACSHA512 hash512 = new HMACSHA512()) { using (RNGCryptoServiceProvider rnd = new RNGCryptoServiceProvider()) { Random cntRnd = new Random (); CryExtInfo extra = new CryExtInfo (); extra.Count = cntRnd.Next (this.MinCount, this.MaxCount); extra.Salt = new byte[64]; //fill the Randomize salt ,the Salt's length is //512bit rnd.GetNonZeroBytes (extra.Salt); using (SHA512CryptoServiceProvider sha512 = new SHA512CryptoServiceProvider()) { byte[] KeyBuffer = new byte[64]; rnd.GetNonZeroBytes (KeyBuffer); KeyBuffer = sha512.ComputeHash (KeyBuffer); extra.Key = KeyBuffer; hash512.Key = KeyBuffer; this.date.ExtraInfo = extra; byte[] pwdBuffer; byte[] pwdDate = Encoding.UTF8.GetBytes (this.Password); //now we add the salt to the string byte[] pwdWithSalt = new byte[pwdDate.Length + extra.Salt.Length]; Array.Copy (pwdDate, pwdWithSalt, pwdDate.Length); Array.Copy (extra.Salt, 0, pwdWithSalt, pwdDate.Length, extra.Salt.Length); pwdBuffer = hash512.ComputeHash (pwdWithSalt); for (int i=0; i<= extra.Count; i++) { pwdBuffer = hash512.ComputeHash (pwdBuffer); } this.date.Password = pwdBuffer; } } } return this.date; }