{"record":{"id":"edf7de98688a14e3","repo":"JeffreySu/WeiXinMPSDK","slug":"hashtype","errorCode":null,"errorMessage":"不支持的文件摘要算法：{hashType}","messagePattern":"不支持的文件摘要算法：(.+?)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/Helpers/TenPayDownloadHelper.cs","lineNumber":143,"sourceCode":"        private static HashAlgorithm CreateHashAlgorithm(string hashType)\n        {\n            switch (hashType?.Replace(\"-\", string.Empty).ToUpperInvariant())\n            {\n                case null:\n                case \"\":\n                    return null;\n                case \"MD5\":\n                    return MD5.Create();\n                case \"SHA1\":\n                    return SHA1.Create();\n                case \"SHA256\":\n                    return SHA256.Create();\n                case \"SHA384\":\n                    return SHA384.Create();\n                case \"SHA512\":\n                    return SHA512.Create();\n                default:\n                    throw new NotSupportedException($\"不支持的文件摘要算法：{hashType}\");\n            }\n        }\n    }\n}\n","sourceCodeStart":125,"sourceCodeEnd":148,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/Helpers/TenPayDownloadHelper.cs#L125-L148","documentation":"CreateHashAlgorithm is a factory mapping normalized hash-type strings (e.g. \"SHA-256\" normalized to \"SHA256\") to .NET HashAlgorithm instances for TenPay V3 download-file digest verification. It throws when hashType, after null/empty short-circuit, does not match MD5, SHA1, SHA256, SHA384 or SHA512 — meaning the digest algorithm named in the download bill/header response is one this helper cannot construct. The offending input is the hashType string supplied by the caller, typically derived from WeChat Pay's response headers.","triggerScenarios":"Calling the download/verify flow with a hashType not in {SHA1, SHA256, SHA384, SHA512} — e.g. \"MD5\", \"sha-256\" (with hyphen), or lowercase strings if the switch is case-sensitive.","commonSituations":"WeChat Pay download metadata usually specifies SHA1; developers pass \"MD5\" out of habit or a casing/format variant that misses the switch cases.","solutions":["Pass hashType exactly as \"SHA1\", \"SHA256\", \"SHA384\", or \"SHA512\".","Normalize casing and remove hyphens before calling (hashType.ToUpper().Replace(\"-\",\"\")).","Default to \"SHA1\" for WeChat Pay bill downloads when unknown."],"exampleFix":"// before\nawait helper.DownloadAndVerifyAsync(url, stream, \"MD5\", md5, timeOut);\n// after\nawait helper.DownloadAndVerifyAsync(url, stream, \"SHA1\", sha1, timeOut);","handlingStrategy":"validation","validationCode":"var allowed = new[]{ \"SHA1\",\"SHA256\",\"SHA384\",\"SHA512\" };\nvar normalized = hashType?.ToUpperInvariant().Replace(\"-\",\"\");\nif (!allowed.Contains(normalized)) throw new ArgumentException($\"不支持的摘要算法: {hashType}\");","typeGuard":null,"tryCatchPattern":"try { await helper.DownloadAndVerifyAsync(url, stream, hashType, hash, timeOut); }\ncatch (NotSupportedException ex) { logger.Error(ex, \"摘要算法不支持\"); }","preventionTips":["Use SHA1 for WeChat Pay bill downloads unless told otherwise","Normalize algorithm names before passing them","Whitelist algorithms in your own API layer"],"tags":["hash","unsupported-algorithm","validation","wechat-pay"],"backgroundTag":"unsupported-enum-value","analyzedSha":"be573f6f94bdbf718dd5f6cdecb137fbc7ff651e","analyzedAt":"2026-09-12T10:01:50.733Z","contentChangedAt":"2026-09-12T10:01:50.733Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}