go - 是否有任何标准协议可以通过网络传输 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
}
当我打印消息时,两边应该是一样的。那么是否有一些标准协议或处理加密文本的东西?
解决方案
推荐阅读
- java - 检查字符串一是否在java中包含字符串二
- github - 如果对 github 操作有条件,是否可以进行模式匹配?
- oracle - Artifactory Derby DB 迁移到 Oracle
- excel - 将特定单元格填充到同一工作簿中另一个工作表的最后一行
- javascript - 添加两个数组,其中两个数组的现有成员和重复成员替换重复的成员
- karate - 关于如何在一个项目中使用 Http 和 ssl 配置空手道
- c# - 操作数类型冲突:加密的 varchar(255) 与 varchar 不兼容 - 带有 Upper 的存储过程 - 始终加密
- visual-studio - 如何在模拟器上运行 UWP 应用并模拟位置?
- css - 在文本上使用 CSS 渐变时的奇怪行为 (Safari)
- mysql - 计算项目并针对每一行显示