Refactor: Replace MD5 with SHA-256 for hashing

This commit is contained in:
SyedaAnshrahGillani
2025-08-14 14:08:49 +05:00
committed by lyingbug
parent f77720155c
commit 92ebf68516
+4 -4
View File
@@ -2,7 +2,7 @@ package service
import ( import (
"context" "context"
"crypto/md5" "crypto/sha256"
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"errors" "errors"
@@ -1326,7 +1326,7 @@ func (s *knowledgeService) GetKnowledgeBatch(ctx context.Context,
return s.repo.GetKnowledgeBatch(ctx, tenantID, ids) return s.repo.GetKnowledgeBatch(ctx, tenantID, ids)
} }
// calculateFileHash calculates MD5 hash of a file // calculateFileHash calculates SHA256 hash of a file
func calculateFileHash(file *multipart.FileHeader) (string, error) { func calculateFileHash(file *multipart.FileHeader) (string, error) {
f, err := file.Open() f, err := file.Open()
if err != nil { if err != nil {
@@ -1334,7 +1334,7 @@ func calculateFileHash(file *multipart.FileHeader) (string, error) {
} }
defer f.Close() defer f.Close()
h := md5.New() h := sha256.New()
if _, err := io.Copy(h, f); err != nil { if _, err := io.Copy(h, f); err != nil {
return "", err return "", err
} }
@@ -1348,7 +1348,7 @@ func calculateFileHash(file *multipart.FileHeader) (string, error) {
} }
func calculateStr(strList ...string) string { func calculateStr(strList ...string) string {
h := md5.New() h := sha256.New()
input := strings.Join(strList, "") input := strings.Join(strList, "")
h.Write([]byte(input)) h.Write([]byte(input))
return hex.EncodeToString(h.Sum(nil)) return hex.EncodeToString(h.Sum(nil))