7
0
gaore-common-sdk-go/sdk/auth/signers/sts_token_signer.go
liangzy c2428de635 1.添加Debug信息
2.添加std_token (md5) 加密方式
2020-08-08 15:09:58 +08:00

42 lines
966 B
Go

package signers
import (
"crypto/md5"
"fmt"
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/auth/credentials"
)
type StsTokenSigner struct {
credential *credentials.StdTokenCredential
}
func (signer *StsTokenSigner) GetAccessKeyId() (string, error) {
return signer.credential.AccessKeyId, nil
}
func (signer *StsTokenSigner) GetAccessKeyFrom() (string, error) {
return signer.credential.AccessKeyFrom, nil
}
func (*StsTokenSigner) GetName() string {
return "MD5"
}
func (signer *StsTokenSigner) Sign(stringToSign, secretSuffix string) string {
secret := signer.credential.AccessKeySecret + secretSuffix
return Md5(stringToSign, secret)
}
func NewStsTokenSigner(credential *credentials.StdTokenCredential) *StsTokenSigner {
return &StsTokenSigner{
credential: credential,
}
}
func Md5(source, secret string) string {
data := []byte(fmt.Sprintf("%s##%s", secret, source))
has := md5.Sum(data)
md5str := fmt.Sprintf("%x", has)
return md5str
}