Esempio n. 1
0
		private void CleanUpInnerRandomStream()
		{
			if(m_randomStream != null) m_randomStream.Dispose();

			if(m_pbInnerRandomStreamKey != null)
				MemUtil.ZeroByteArray(m_pbInnerRandomStreamKey);
		}
Esempio n. 2
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);
        }