{"record":{"id":"a55bd7d00468e98c","repo":"peass-ng/PEASS-ng","slug":"invalid-date-string","errorCode":null,"errorMessage":"invalid date string: ","messagePattern":"invalid date string: ","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerGeneralizedTime.cs","lineNumber":76,"sourceCode":"         * for local time, or Z+-HHMM on the end, for difference between local\n         * time and UTC time. The fractional second amount f must consist of at\n         * least one number with trailing zeroes removed.\n         *\n         * @param time the time string.\n         * @exception ArgumentException if string is an illegal format.\n         */\n        public DerGeneralizedTime(\n            string time)\n        {\n            this.time = time;\n\n            try\n            {\n                ToDateTime();\n            }\n            catch (FormatException e)\n            {\n                throw new ArgumentException(\"invalid date string: \" + e.Message);\n            }\n        }\n\n        /**\n         * base constructor from a local time object\n         */\n        public DerGeneralizedTime(\n            DateTime time)\n        {\n#if PORTABLE\n            this.time = time.ToUniversalTime().ToString(@\"yyyyMMddHHmmss\\Z\");\n#else\n            this.time = time.ToString(@\"yyyyMMddHHmmss\\Z\");\n#endif\n        }\n\n        internal DerGeneralizedTime(\n            byte[] bytes)","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerGeneralizedTime.cs#L58-L94","documentation":"The DerGeneralizedTime(string) constructor validates the date string immediately by calling ToDateTime(); if that raises FormatException, the constructor rethrows it as ArgumentException('invalid date string: ...'). Only properly formatted GeneralizedTime strings (yyyyMMddHHmmss... with optional fraction/timezone) are accepted.","triggerScenarios":"Calling new DerGeneralizedTime(s) with a string that is not a valid DER GeneralizedTime: missing date parts, bad separators, invalid timezone suffix, non-digit characters, or an impossible date.","commonSituations":"Strings from certificates, logs, or user input parsed as GeneralizedTime; locale-dependent DateTime strings (e.g. '01/02/2026 3pm') fed in directly; truncated timestamp fields from corrupt data.","solutions":["Ensure the string is DER GeneralizedTime format, e.g. '20260901123000Z' or '20260901123000.123+0200'","Normalize the value first: parse to DateTime yourself (DateTime.Parse/DateTimeOffset) and use the DerGeneralizedTime(DateTime) constructor","Trim garbage: verify with a regex like ^\\d{14}(\\.\\d+)?(Z|[+-]\\d{4})?$ before constructing"],"exampleFix":"// before\nvar gt = new DerGeneralizedTime(userString); // may throw\n// after\nif (!DateTime.TryParse(userString, CultureInfo.InvariantCulture, DateTimeStyles.None, out var dt))\n    throw new FormatException(\"Not a valid date: \" + userString);\nvar gt = new DerGeneralizedTime(dt);","handlingStrategy":"validation","validationCode":"if (Regex.IsMatch(s ?? \"\", @\"^\\d{14}(\\.\\d+)?(Z|[+-]\\d{4})?$\"))\n{ var gt = new DerGeneralizedTime(s); }","typeGuard":null,"tryCatchPattern":"try { var gt = new DerGeneralizedTime(s); }\ncatch (ArgumentException ex) when (ex.Message.StartsWith(\"invalid date string\")) { /* normalize or reject */ }","preventionTips":["Regex-validate GeneralizedTime strings before constructing","Use the DateTime constructor with InvariantCulture-parsed dates"],"tags":["asn1","bouncycastle","date-parsing","argument-validation"],"backgroundTag":"invalid-date-string","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}