是否有任何标准协议可通过网络传输RSA加密文本?

时间:2019-04-29 06:45:41

标签: go encryption tcp client-server rsa

我有一个客户端和一个服务器端代码。我必须从客户端接收一条消息作为输入,对其进行加密并将其发送到服务器。但是,当我在服务器端打印此加密消息时,它与客户端上的消息不同。这是我的操作方式:

首先,我正在使用rsa.EncryptOAEP()函数对邮件进行加密。该消息是结构的成员,该结构也具有其他成员。我正在使用gob包对该结构进行编码,然后将其发送到服务器。

这是客户端代码的片段:

func SocketClient() {
    conn, err := net.Dial("tcp", ":9000")
    if err != nil {
        log.Fatalln(err)
    }
    defer conn.Close()
    enc := gob.NewEncoder(conn)
    buff, _ := input_reader.ReadBytes('\n')    //this is the message to be encrypted
    label := []byte("")
    hash := sha256.New()
    ciphertext, _ := rsa.EncryptOAEP(
        hash,
        rand.Reader,
        &receiverPublicKey,
        buff,
        label,
    )
    fmt.Printf("%s",ciphertext) //this is to check if the text is same or not
    block.Message = ciphertext //this is the struct to be sent over network
    enc.Encode(block)
}

这是服务器端代码:

func handleConn(conn net.Conn) {
    defer conn.Close()
    dec := gob.NewDecoder(conn)
    dec.Decode(&block)
    fmt.Printf("%s",block.Message) //it is different from the text printed in client side code
}

当我打印消息时,其两侧应该相同。那么,是否有一些标准协议或某种可以处理加密文本的东西?

0 个答案:

没有答案