提交 47579ba0 编写于 作者: J jiazhiguang 提交者: jia zhang

Base64 encode the signatrue when sending signature body from server and base64...

Base64 encode the signatrue when sending signature body from server and base64 decode signature when retriving signature  bodyfrom client
上级 9bffcfcb
...@@ -3,6 +3,7 @@ package client ...@@ -3,6 +3,7 @@ package client
import ( import (
"bytes" "bytes"
"crypto/tls" "crypto/tls"
"encoding/base64"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
...@@ -91,7 +92,12 @@ func (c *pkcs1Client) Sign(data []byte) (signature []byte, publicKey []byte, err ...@@ -91,7 +92,12 @@ func (c *pkcs1Client) Sign(data []byte) (signature []byte, publicKey []byte, err
glog.Errorf("failed to unmarshal sign response,%v", err) glog.Errorf("failed to unmarshal sign response,%v", err)
return nil, nil, err return nil, nil, err
} }
return []byte(payload.Signature), []byte(payload.PublicKey), nil decode, err := base64.StdEncoding.DecodeString(payload.Signature)
if err != nil {
glog.Errorf("failed to decode signature,%v", err)
return nil, nil, err
}
return decode, []byte(payload.PublicKey), nil
} }
func (c *pkcs1Client) GetStandard() SignStandard { func (c *pkcs1Client) GetStandard() SignStandard {
......
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"crypto/rand" "crypto/rand"
"crypto/rsa" "crypto/rsa"
"crypto/sha256" "crypto/sha256"
"encoding/base64"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
...@@ -34,7 +35,7 @@ func (s *ApiServer) pkcs1Handler(c *gin.Context) { ...@@ -34,7 +35,7 @@ func (s *ApiServer) pkcs1Handler(c *gin.Context) {
return return
} }
payload.Signature = string(signedBytes) payload.Signature = base64.StdEncoding.EncodeToString(signedBytes)
bytes, err := ioutil.ReadFile(s.publicKeyFilePath) bytes, err := ioutil.ReadFile(s.publicKeyFilePath)
if err != nil { if err != nil {
glog.Errorf("failed to parse public key, public key path: %s, err:%v", s.publicKeyFilePath, err.Error()) glog.Errorf("failed to parse public key, public key path: %s, err:%v", s.publicKeyFilePath, err.Error())
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册