{"record":{"id":"0e0133e25cb86273","repo":"jstedfast/MailKit","slug":"no-hash-value-computed","errorCode":null,"errorMessage":"No hash value computed.","messagePattern":"No hash value computed\\.","errorType":"validation","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"MailKit/Security/Ntlm/HMACMD5.cs","lineNumber":55,"sourceCode":"\t\treadonly HMac hash = new HMac (new MD5Digest ());\n\t\tbyte[] hashValue, key;\n\t\tbool disposed;\n\n\t\tpublic HMACMD5 (byte[] key)\n\t\t{\n\t\t\tKey = key;\n\t\t}\n\n\t\t~HMACMD5 ()\n\t\t{\n\t\t\tDispose (false);\n\t\t}\n\n\t\tpublic byte[] Hash\n\t\t{\n\t\t\tget {\n\t\t\t\tif (hashValue == null)\n\t\t\t\t\tthrow new InvalidOperationException (\"No hash value computed.\");\n\n\t\t\t\treturn hashValue;\n\t\t\t}\n\t\t}\n\n\t\tpublic byte[] Key {\n\t\t\tget { return key; }\n\t\t\tset {\n\t\t\t\tif (value == null)\n\t\t\t\t\tthrow new ArgumentNullException (nameof (value));\n\n\t\t\t\tif (key != null)\n\t\t\t\t\tArray.Clear (key, 0, key.Length);\n\n\t\t\t\tkey = value;\n\t\t\t\tInitialize ();\n\t\t\t}\n\t\t}","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Security/Ntlm/HMACMD5.cs#L37-L73","documentation":"HMACMD5.Hash throws InvalidOperationException(\"No hash value computed.\") when hashValue is null, i.e. Hash is read before ComputeHash has ever been called. The Hash property only exposes a previously computed digest.","triggerScenarios":"Accessing hmac.Hash immediately after construction or after Key was reassigned (which resets state) without calling ComputeHash first.","commonSituations":"Debug/logging code reading .Hash speculatively; re-keying then assuming the old hash is still available.","solutions":["Call ComputeHash before reading Hash","Cache the hash returned by ComputeHash instead of re-reading the property","Catch InvalidOperationException and treat as 'digest not yet computed'"],"exampleFix":"// before\nvar hmac = new HMACMD5(key);\nvar digest = hmac.Hash; // throws\n// after\nvar hmac = new HMACMD5(key);\nvar digest = hmac.ComputeHash(data);","handlingStrategy":"validation","validationCode":"if (hmacHashNotComputed) throw new InvalidOperationException(\"call ComputeHash before reading Hash\");","typeGuard":"bool HasDigest(HMACMD5 h) => h.Hash != null;","tryCatchPattern":"try { var d = hmac.Hash; } catch (InvalidOperationException) { d = hmac.ComputeHash(data); }","preventionTips":["Always take the digest from ComputeHash's return value","Remember setting Key resets hash state","Avoid speculative Hash reads in logging"],"tags":["csharp","hmac","invalid-state"],"backgroundTag":"invalid-state-transition","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}