service/library/contentaudit/video_moderation/sign.go

34 lines
816 B
Go
Raw Normal View History

2024-04-26 10:46:37 +08:00
package videomoderation
import (
"crypto/sha256"
"fmt"
video_moderation_proto "service/api/proto/video_moderation/proto"
"service/library/logger"
"strings"
)
func VerifySign(req *video_moderation_proto.ExtVideoModerationReq) error {
uid := _defaultConfig.AliAcctId
seed := _defaultConfig.Seed
content := req.Content
signStr := uid + seed + content
// sha256加密
hash := sha256.Sum256([]byte(signStr))
// 验签
signedStr := fmt.Sprintf("%X", hash)
signedStr = strings.ToLower(signedStr)
if req.CheckSum != signedStr {
logger.Info("content:")
fmt.Printf("%s\n", req.Content)
logger.Info("checksum:")
fmt.Printf("%s\n", req.CheckSum)
logger.Info("signedStr:")
fmt.Printf("%s\n", signedStr)
fmt.Printf("verify sign failed\n")
return fmt.Errorf("verify sign failed")
}
return nil
}