コード例 #1
0
ファイル: PwGenerator.cs プロジェクト: nagyist/mackeepass
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }