当你只知道私钥时,是否有可能知道 RSA 的 public 密钥

Is it possible to know RSA's public key while you only know private key

我正在尝试为我的移动应用程序服务实施椭圆曲线 Diffie Hellman。作为我实施的最后阶段,我需要用 RSA 加密 ECDH 的公钥。但是由于我们只能使用 RSA 的 publicKey 加密并使用 privateKey 解密,我认为我应该将 privateKey 提供给客户端并保留 publicKey 服务,我对公开私钥是否可以感到困惑。 是否可以从私钥中提取公钥?

return JsonConvert.SerializeObject(new
        {
            responseVal = ResponseVal,
            responseText = ResponseText,
            ServerECDHPublicKey = serverPublicKey,
            ServerECDHPublicKey_AES = Security.EncryptAES(null, serverPublicKey, aes),
            AESKey_RSA = Security.EncryptRSA(Encoding.UTF8.GetString(aes.Key))
        });

评论里有几个答案。所以只发布一般想法作为答案。

I am trying to implement Elliptic Curve Diffie Hellman for my mobile app's service.

好的。所以理解就是密钥推导是在应用层。如果像 Ry 提到的那样使用 HTTPS (TLS),它会为您完成(可以这么说)。

As last stage of my implementation i need to encrypt the publickey of ECDH with RSA . But since we only can encrypt with RSA's publicKey and decrypt with privateKey, i am thinking that i should give the privateKey to the clients and keep publicKey to service, I am little confused about whether its okay to expose the private key or not.

再次如 Ry 所述,您实际上需要 'sign' 临时 public 密钥。这样你就可以把私钥留给自己(你在评论中发布的 视频 link 中也提到了这一点)并与客户端共享 public 密钥- 按照设计。

Is it possible to extract the publicKey from privateKey ?

实际上没有。虽然公用参数很少,但public和私钥之所以这样称呼,是因为它们作为一个整体,具有独特的参数。例如,在 RSA 的情况下,public 密钥由 'public' 指数和模数组成,私钥由 'private' 指数和 指数模数。因此,虽然可以 'guess' public 指数(或者只是在 ssl 握手期间从服务器证书中提取它),但严格来说,不可能从私钥中提取它。

更新:您也可以考虑使用 JWE (JSON-Web-Encryption) in conjunction with JWS (JSON-Web-Signature)。它几乎可以满足您的需求。

此致,

拉文德拉