-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add hmac-sm3 example; rename MDAlgo to DigestAlgo
Add example for HMAC-SM3. Rename MDAlgo to DigestAlgo.
- Loading branch information
1 parent
c5bd3b9
commit c698f20
Showing
7 changed files
with
86 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2025 The Tongsuo Project Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License 2.0 (the "License"). You may not use | ||
// this file except in compliance with the License. You can obtain a copy | ||
// in the file LICENSE in the source distribution or at | ||
// https://github.com/Tongsuo-Project/tongsuo-go-sdk/blob/main/LICENSE | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/tongsuo-project/tongsuo-go-sdk/crypto" | ||
) | ||
|
||
func main() { | ||
key := []byte("1234567890123456") | ||
|
||
h, err := crypto.NewHMAC(key, crypto.DigestSM3) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
_, err = h.Write([]byte("hello")) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
_, err = h.Write([]byte(" world")) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
res, err := h.Final() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Printf("HMAC-SM3(hello world)=%x\n", res) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters