我正在尝试从pem文件中导入公共密钥,以便对其进行加密并将其发送给接收者,但是却出现了错误。
func importPublicKey(publicKeyString string) *rsa.PublicKey{
block, _ := pem.Decode([]byte(publicKeyString))
publicKey, err := x509.ParsePKCS1PublicKey(block.Bytes)
if err != nil {
println(err.Error())
}
return publicKey
}
publicKeyString := `-----BEGIN RSA PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAz1Ibsf4IGAs1ymoew4hR
MQUJwIGotca3kiHOeZzuzosuw58z8FFEDQt+PcxjTsx3mvo0uK04oL5CGorQZrTl
jJroZj5B2IwmHu2l1wpoKjaPbQDWu8RoIKlObaq9ENcqmH2/yvxUIBcJ0M9e5Tky
UslTmqUdZCSDljPO+u30HkBVRqs5Z/bE82BfYMKJ3oDBdWMfiM2nyxGb9ynlml5B
dC3USyVIr9NE7NEW5y78ru2F1/zmnPdfnOp4FgsgwLrinML7LZ+TUKT2zfwsVhJK
IKl6WFwDQUspi1Oo5km3AsvGtGqBynCyWtj3ZPHMlCQplEusDmF9flyiABgvBrwk
uQIDAQAB
-----END RSA PUBLIC KEY-----
`
我收到asn1: structure error: tags don't match (2 vs {class:0 tag:16 length:13 isCompound:true}) {optional:false explicit:false application:false private:false defaultValue:<nil> tag:<nil> stringType:0 timeType:0 set:false omitEmpty:false} @2
的错误消息
如何导入此公钥?