public static PwgError Generate(out ProtectedString psOut, PwProfile pwProfile, byte[] pbUserEntropy, CustomPwGeneratorPool pwAlgorithmPool) { Debug.Assert(pwProfile != null); if (pwProfile == null) { throw new ArgumentNullException("pwProfile"); } CryptoRandomStream crs = CreateCryptoStream(pbUserEntropy); PwgError e = PwgError.Unknown; if (pwProfile.GeneratorType == PasswordGeneratorType.CharSet) { e = CharSetBasedGenerator.Generate(out psOut, pwProfile, crs); } else if (pwProfile.GeneratorType == PasswordGeneratorType.Pattern) { e = PatternBasedGenerator.Generate(out psOut, pwProfile, crs); } else if (pwProfile.GeneratorType == PasswordGeneratorType.Custom) { e = GenerateCustom(out psOut, pwProfile, crs, pwAlgorithmPool); } else { Debug.Assert(false); psOut = ProtectedString.Empty; } return(e); }
public static PwgError Generate(ProtectedString psOutBuffer, PwProfile pwProfile, byte[] pbUserEntropy) { Debug.Assert(psOutBuffer != null); if (psOutBuffer == null) { throw new ArgumentNullException("psOutBuffer"); } Debug.Assert(pwProfile != null); if (pwProfile == null) { throw new ArgumentNullException("pwProfile"); } psOutBuffer.Clear(); CryptoRandomStream crs = CreateCryptoStream(pbUserEntropy); PwgError e = PwgError.Unknown; if (pwProfile.GeneratorType == PasswordGeneratorType.CharSet) { e = CharSetBasedGenerator.Generate(psOutBuffer, pwProfile, crs); } else if (pwProfile.GeneratorType == PasswordGeneratorType.Pattern) { e = PatternBasedGenerator.Generate(psOutBuffer, pwProfile, crs); } else { Debug.Assert(false); } return(e); }
public static PwgError Generate(out ProtectedString psOut, PwProfile pwProfile, byte[] pbUserEntropy, CustomPwGeneratorPool pwAlgorithmPool) { Debug.Assert(pwProfile != null); if (pwProfile == null) { throw new ArgumentNullException("pwProfile"); } PwgError e = PwgError.Unknown; CryptoRandomStream crs = null; byte[] pbKey = null; try { crs = CreateRandomStream(pbUserEntropy, out pbKey); if (pwProfile.GeneratorType == PasswordGeneratorType.CharSet) { e = CharSetBasedGenerator.Generate(out psOut, pwProfile, crs); } else if (pwProfile.GeneratorType == PasswordGeneratorType.Pattern) { e = PatternBasedGenerator.Generate(out psOut, pwProfile, crs); } else if (pwProfile.GeneratorType == PasswordGeneratorType.Custom) { e = GenerateCustom(out psOut, pwProfile, crs, pwAlgorithmPool); } else { Debug.Assert(false); psOut = ProtectedString.Empty; } } finally { if (crs != null) { crs.Dispose(); } if (pbKey != null) { MemUtil.ZeroByteArray(pbKey); } } return(e); }