data = "hello"
rsa = OpenSSL::PKey::RSA.new(File.read("xxx.pem"))
string1 = rsa.public_encrypt(data)
string2 = Base64.urlsafe_encode64(string1)
总是签名不过,不知道这个位置哪里写错了,用 go 写的签名可以过
// 部分省略
data = "hello"
path := "xxx.pem"
publickey, errfile := LoadFile(path)
block, _ := pem.Decode(publickey)
pubInterface, err := x509.ParsePKIXPublicKey(block.Bytes)
pub := pubInterface.(*rsa.PublicKey)
partLen := pub.N.BitLen()/8 - 11
chunks := split([]byte(data), partLen)
buffer := bytes.NewBufferString("")
for _, chunk := range chunks {
bytes, err := rsa.EncryptPKCS1v15(rand.Reader, pub, chunk)
if err != nil {
return "", err
}
buffer.Write(bytes)
}
return base64.RawURLEncoding.EncodeToString(buffer.Bytes())