forked from gokalkan/gokalkan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhash.go
42 lines (33 loc) · 934 Bytes
/
hash.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package gokalkan
import (
"encoding/base64"
"github.com/olegmlsn/gokalkan/ckalkan"
)
func (cli *Client) HashSHA256(data []byte) (hashed []byte, err error) {
flags := ckalkan.FlagInBase64 | ckalkan.FlagOutBase64
algo := ckalkan.HashAlgoSHA256
dataB64 := base64.StdEncoding.EncodeToString(data)
hashedB64, err := cli.kc.HashData(algo, dataB64, flags)
if err != nil {
return nil, err
}
raw, err := base64.StdEncoding.DecodeString(hashedB64)
if err != nil {
return nil, err
}
return raw, nil
}
func (cli *Client) HashGOST95(data []byte) (hashed []byte, err error) {
flags := ckalkan.FlagInBase64 | ckalkan.FlagOutBase64
algo := ckalkan.HashAlgoGOST95
dataB64 := base64.StdEncoding.EncodeToString(data)
hashedB64, err := cli.kc.HashData(algo, dataB64, flags)
if err != nil {
return nil, err
}
raw, err := base64.StdEncoding.DecodeString(hashedB64)
if err != nil {
return nil, err
}
return raw, nil
}