{"record":{"id":"1d10165dda85a7d0","repo":"peass-ng/PEASS-ng","slug":"basedigest-output-not-large-enough-to-support-leng","errorCode":null,"errorMessage":"baseDigest output not large enough to support length","messagePattern":"baseDigest output not large enough to support length","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/digests/ShortenedDigest.cs","lineNumber":33,"sourceCode":"\t\t/**\n\t\t* Base constructor.\n\t\t*\n\t\t* @param baseDigest underlying digest to use.\n\t\t* @param length length in bytes of the output of doFinal.\n\t\t* @exception ArgumentException if baseDigest is null, or length is greater than baseDigest.GetDigestSize().\n\t\t*/\n\t\tpublic ShortenedDigest(\n\t\t\tIDigest\tbaseDigest,\n\t\t\tint\t\tlength)\n\t\t{\n\t\t\tif (baseDigest == null)\n\t\t\t{\n\t\t\t\tthrow new ArgumentNullException(\"baseDigest\");\n\t\t\t}\n\n\t\t\tif (length > baseDigest.GetDigestSize())\n\t\t\t{\n\t\t\t\tthrow new ArgumentException(\"baseDigest output not large enough to support length\");\n\t\t\t}\n\n\t\t\tthis.baseDigest = baseDigest;\n\t\t\tthis.length = length;\n\t\t}\n\n\t\tpublic string AlgorithmName\n\t\t{\n\t\t\tget { return baseDigest.AlgorithmName + \"(\" + length * 8 + \")\"; }\n\t\t}\n\n\t\tpublic int GetDigestSize()\n\t\t{\n\t\t\treturn length;\n\t\t}\n\n\t\tpublic void Update(byte input)\n\t\t{","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/digests/ShortenedDigest.cs#L15-L51","documentation":"ShortenedDigest can only truncate to length bytes at most as large as the base digest's output. The constructor throws ArgumentException when length > baseDigest.GetDigestSize(), since it cannot produce more bytes than the underlying algorithm provides.","triggerScenarios":"new ShortenedDigest(new Md5Digest(), 32) — requesting 32 bytes from a 16-byte digest; similarly Sha1 with length > 20.","commonSituations":"Requesting SHA-256-sized output while wrapping SHA-1; configuring 'shortened' sizes without checking the base algorithm's digest size.","solutions":["Pass length <= baseDigest.GetDigestSize() in bytes.","Use a larger base digest (e.g. Sha512Digest) if you need longer output.","Check GetDigestSize() at runtime before construction."],"exampleFix":"// before\nvar d = new ShortenedDigest(new Sha1Digest(), 32);\n// after\nvar d = new ShortenedDigest(new Sha256Digest(), 32);","handlingStrategy":"validation","validationCode":"if (length > baseDigest.GetDigestSize()) throw new ArgumentOutOfRangeException(nameof(length));","typeGuard":"bool CanShorten(IDigest baseDigest, int length) => baseDigest != null && length <= baseDigest.GetDigestSize();","tryCatchPattern":"try { d = new ShortenedDigest(baseDigest, len); }\ncatch (ArgumentException) { d = new ShortenedDigest(new Sha512Digest(), len); }","preventionTips":["Compare requested length (bytes) against GetDigestSize() (also bytes) before wrapping.","Choose a base digest at least as large as the desired output.","Document lengths in bytes everywhere to avoid bit/byte confusion."],"tags":["csharp","argument-validation","bouncycastle","hash"],"backgroundTag":"invalid-hash-parameter","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}