我需要使用 RSA-2048 服務器公鑰加密客戶端私鑰。我知道私鑰顯然比公鑰長,我不確定這是否可能......但我看到類似的任務是在Python中完成的,所以我想知道你的意見。/* main */clientPrivateKey, _ := generateRsaPair(2048)_, serverPublicKey := generateRsaPair(2048)clientPrivateKeyAsByte := privateKeyToBytes(clientPrivateKey)encryptWithPublicKey(clientPrivateKeyAsByte, serverPublicKey) 致命錯誤 crypto/rsa:消息對于 RSA 公鑰大小來說太長/* Functions */func generateRsaPair(bits int) (*rsa.PrivateKey, *rsa.PublicKey) { privkey, err := rsa.GenerateKey(rand.Reader, bits) if err != nil { log.Error(err) } return privkey, &privkey.PublicKey}func encryptWithPublicKey(msg []byte, pub *rsa.PublicKey) []byte { hash := sha512.New() ciphertext, err := rsa.EncryptOAEP(hash, rand.Reader, pub, msg, nil) checkError(err) return ciphertext}func privateKeyToBytes(priv *rsa.PrivateKey) []byte { privBytes := pem.EncodeToMemory( &pem.Block{ Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(priv), }, ) return privBytes}
使用 RSA-2048 服務器公鑰加密客戶端私鑰
12345678_0001
2023-07-04 17:08:31