signer_v2.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Licensed under the Apache License, Version 2.0 (the "License");
  3. * you may not use this file except in compliance with the License.
  4. * You may obtain a copy of the License at
  5. *
  6. * http://www.apache.org/licenses/LICENSE-2.0
  7. *
  8. * Unless required by applicable law or agreed to in writing, software
  9. * distributed under the License is distributed on an "AS IS" BASIS,
  10. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. * See the License for the specific language governing permissions and
  12. * limitations under the License.
  13. */
  14. package signers
  15. import (
  16. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  17. )
  18. type SignerV2 struct {
  19. credential *credentials.RsaKeyPairCredential
  20. }
  21. func (signer *SignerV2) GetExtraParam() map[string]string {
  22. return nil
  23. }
  24. func NewSignerV2(credential *credentials.RsaKeyPairCredential) *SignerV2 {
  25. return &SignerV2{
  26. credential: credential,
  27. }
  28. }
  29. func (*SignerV2) GetName() string {
  30. return "SHA256withRSA"
  31. }
  32. func (*SignerV2) GetType() string {
  33. return "PRIVATEKEY"
  34. }
  35. func (*SignerV2) GetVersion() string {
  36. return "1.0"
  37. }
  38. func (signer *SignerV2) GetAccessKeyId() (accessKeyId string, err error) {
  39. return signer.credential.PublicKeyId, err
  40. }
  41. func (signer *SignerV2) Sign(stringToSign, secretSuffix string) string {
  42. secret := signer.credential.PrivateKey
  43. return Sha256WithRsa(stringToSign, secret)
  44. }