/// <summary> /// Gets the crypto version. /// </summary> /// <returns>The crypto version.</returns> /// <param name="Date">Date.</param> public static string GetCryptoVersion(byte[] Date) { using (MemoryStream ms = new MemoryStream()) { BinaryFormatter bf = new BinaryFormatter(); ms.Write(Date, 0, Date.Length); ms.Position = 0; PasswdBase tmp = bf.Deserialize(ms) as PasswdBase; if (tmp == null) { return(null); } return(tmp.VersionHash); } }
/// <summary> /// Check the specified Date. /// the date is from disk or datebase /// </summary> /// <param name="Date">Date.</param> public bool Check(byte[] Date) { using (MemoryStream ms = new MemoryStream()) { BinaryFormatter bf = new BinaryFormatter(); ms.Write(Date, 0, Date.Length); ms.Position = 0; PasswdBase tmp = bf.Deserialize(ms) as PasswdBase; if (tmp == null) { return(false); } //show this password is not in this check if (tmp.VersionHash != this.GetGUID()) { return(false); } return(this.CheckSecret(tmp)); } }
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)); } }
/// <summary> /// Initializes a new instance of the <see cref="AbPasswdPlugin.Crypt"/> class. /// </summary> /// <param name="passwd">Passwd.</param> public PBKDF2(string passwd) : base(passwd) { this.date = new PasswdBase(); }
/// <summary> /// Initializes a new instance of the <see cref="AbPasswdPlugin.Crypt"/> class. /// </summary> public PBKDF2() : base("", 100, 200) { this.date = new PasswdBase(); }
/// <summary> /// Checks the secret. /// </summary> /// <returns><c>true</c>, if secret was checked, <c>false</c> otherwise.</returns> /// <param name="info">Info.</param> protected abstract bool CheckSecret(PasswdBase info);
/// <summary> /// Initializes a new instance of the <see cref="AbPasswdPlugin.Crypt"/> class. /// </summary> public PBKDF2() : base("",100,200) { this.date = new PasswdBase (); }
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); } }
/// <summary> /// Initializes a new instance of the <see cref="AbPasswdPlugin.Crypt"/> class. /// </summary> /// <param name="passwd">Passwd.</param> public PBKDF2(string passwd) : base(passwd) { this.date = new PasswdBase (); }