RSA - 客户端(在服务器上下文中)如何加密/解密传入的数据? [英] RSA - How can the client (in server context) encrypt/decrypt incoming data?

查看:253
本文介绍了RSA - 客户端(在服务器上下文中)如何加密/解密传入的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法了解RSA的工作原理。



这里是我想要做的:



我有一个使用RSA并有私人和公共密钥的服务器。根据我的理解,在连接时,服务器以未加密的方式将公共密钥发送到服务器。如果您愿意,可以使用某种握手方式。



以加密的方式。要建立这种方式,我如何能够加密客户端发送的内容,并解密客户端接收的内容(从客户端角度来看)。



在服务器端加密数据由私钥解密,但是我无法解密客户端中没有私钥的数据...我在客户端不能拥有,因为它是秘密的。



这让我很困惑,我缺少明显的东西,还是需要第二个私钥?



提前感谢!

如同您已经指出的, RSA 是一种非对称加密方案,意味着:

  c = E(pub_key,m)// ciphertext = encryption(public key,message)
m = D(pri_key,c)// message = ,密文)

相比之下,对称加密方案(例如 AES )的工作原理如下:

  c = E(key,m)
m = E b $ b

换句话说,相同的密钥用于加密和解密。



这就是非对称密码系统的作用。






因此,基本上如何将一个原始非常脆弱!)密钥交换可以看起来:


  1. 服务器向客户端发送他的公钥 pub_key_S
  2. 客户端向服务器发送使用服务器公钥加密的公钥
    c = E(pub_key_S,pub_key_C)
  3. 服务器用其私钥解密 c pub_key_C = D(pri_key_S,c)
  4. 服务器生成新的随机对称密钥 key_CS
  5. 服务器使用客户端的公钥加密新生成的密钥 c = E (pub_key_C,key_CS)
  6. 服务器向客户端发送 c
  7. 私钥 pri_key_C key_CS = D(pri_key_C,c)

现在,客户端和服务器有一个共享的密钥 key_CS ,可以用它们为正在进行的会话进行安全通信。






这样的协议在实践中非常复杂,包括证书,数字签名,散列码等等。可能最广泛使用的协议是 SSL或TLS 。 (例如 https )。



如果您对这类链接感兴趣,建议您查看该链接协议。


I have trouble understanding exactly how RSA works. Many examples and definitions attempt to explain but use a vague context.

So here is what I want to do:

I have a server that uses RSA and has a private and public key. From what I understand, upon connection the server sends the public key to the server in an unencrypted manner.. some kind of handshake if you will.

Further traffic would then occur in an encrypted fashion. To establish this fashion how would I be able to both encrypt what the client sends, and decrypt what the client receives (from client-sided perspective).

On server side encrypted data gets decrypted by the private key but I can't decrypt data in the client without that private key... that I can't have in the client because it's secret.

This confuses me, am I missing something obvious or is there need of a second private key?

Thanks in advance!

解决方案

As you have already pointed out is RSA an asymmetric encryption scheme, that means:

c = E(pub_key, m) // ciphertext = encryption(public key,  message)
m = D(pri_key, c) // message    = decryption(private key, ciphertext)

In contrast a symmetric encryption scheme (such as fore example AES) works the following:

c = E(key, m)
m = E(key, c)

In other words the same key is used for encryption and decryption.

And that is where the asymmetric cryptosystem comes into play. It allows to parties to securely exchange a secret key for symmetric encryption.


So basically how a primitive (but very vulnerable!) key exchange could look:

  1. server sends to client his public key pub_key_S
  2. client sends to server his public key encrypted with the server's public key
    c = E(pub_key_S, pub_key_C)
  3. server decrypts c with his private key pub_key_C = D(pri_key_S, c)
  4. server generates a new random symmetric secret key key_CS
  5. server encrypts the newly generated key with the client's public key c = E(pub_key_C, key_CS)
  6. server sends c to the client
  7. client decrypts ciphertext with his private key pri_key_C key_CS = D(pri_key_C, c)

Now Client and Server have a shared secret key key_CS which they can use to securely communicate for the ongoing session.


Such a protocol is in practice quite a bit more complicated, including certificates, digital signatures, hashcodes and so on. The probably most widely used protocol is SSL or TLS. (for in example https).

I recommend you to check out that link if you are interested in the details of such a protocol.

这篇关于RSA - 客户端(在服务器上下文中)如何加密/解密传入的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆