tencent cloud

Super App Platform Signature & Verification
Last updated: 2025-12-05 22:48:45
Super App Platform Signature & Verification
Last updated: 2025-12-05 22:48:45

Signature Method

A string generated by encrypting data using AES-ECB and then encoding the result in hexadecimal.

Signature Parameters

The secret key is the SecretKey defined in Configuration Management.

Example

func TestGenerateSignature(t *testing.T) {
// test data
secretKey := "MBMIvsoijBSTqLPoCHYinLXKvlaCKfev"
timestamp := fmt.Sprintf("%v", time.Now().UnixMilli())
encryptBytes, err := EncryptECB([]byte(timestamp), []byte(secretKey))
if err != nil {
fmt.Println(err)
}
signature := hex.EncodeToString(encryptBytes)
fmt.Println(signature)
}

func EncryptECB(plaintext, secretKey []byte) ([]byte, error) {

block, err := aes.NewCipher(secretKey)
if err != nil {
return nil, errors.Errorf("Error: NewCipher(%d bytes) = %s", len(secretKey), err)
}
padded := PKCS7Padding(plaintext, block.BlockSize())
ciphertext := make([]byte, len(padded))

for bs, be := 0, block.BlockSize(); bs < len(padded); bs, be = bs+block.BlockSize(), be+block.BlockSize() {
block.Encrypt(ciphertext[bs:be], padded[bs:be])
}

return ciphertext, nil
}
func PKCS7Padding(ciphertext []byte, blockSize int) []byte {
padding := blockSize - len(ciphertext)%blockSize
padtext := bytes.Repeat([]byte{byte(padding)}, padding)
return append(ciphertext, padtext...)
}


Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback