RSA在加密句子时如何工作? [英] How does RSA work while encrypting a sentence?

查看:133
本文介绍了RSA在加密句子时如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习RSA加密,并且已经了解如何加密单个字母。我在理解RSA加密句子时如何工作方面遇到问题。

I'm learning about RSA encryption and I have understood how to encrypt a single letter. I have problems understanding how does RSA work while encrypting a sentence.

例如:单字母加密:A
Encryption = A ^ e(mod n)

For eg: Single letter encryption: A
Encryption= A^e (mod n)

但是用一句话。例如:句子加密:Hello World

But in a sentence. For eg: Sentence encryption: Hello World

每个单词都被加密还是整个句子都被加密了?

Does each word get encrypted or does the sentences as a whole get encrypted?

推荐答案

都没有。实际上,RSA几乎总是与对称密码(例如AES)结合使用来加密较大的密文。

Neither. In practice RSA is almost always coupled with a symmetric cipher such as AES to encrypt larger ciphertext.

RSA本身当然不能区分单词和句子。 RSA(密码原语)在数字上运行。 PKCS#1中定义的RSA,其中在模幂运算之前或之后进行填充/取消填充,但是对位进行操作。反过来,密码库则对字节进行操作,因为字节通常是可以直接在内存中寻址的最小元素。

RSA in itself certainly doesn't distinguish between words and sentences. RSA - the cryptographic primitive - operates on numbers. RSA as defined in PKCS#1, where the modular exponentiation is preceded or followed by padding / unpadding however operates on bits. In turn, cryptographic libraries operate on bytes, as a byte is generally the smallest element that can be addressed directly within memory.

要确保RSA的安全性,必须将其与安全填充模式(例如PKCS#1 v1.5兼容填充或OAEP)一起使用。但是,这只会允许对相对较小的消息进行加密。因此,RSA通常用于加密随机生成的AES密钥(16、24或32字节),然后再用于加密几乎任何大小的实际纯文本消息。也可以使用例如RSA-KEM 建立一个特定的密钥,而不是直接加密一个密钥。一起使用RSA和AES称为混合加密系统,因为它同时包含非对称和对称加密。

For RSA to be secure it needs to be used with a secure padding mode such as PKCS#1 v1.5 compatible padding or OAEP. However, that will only allow relatively small messages to be encrypted. So RSA is commonly used to encrypt a randomly generated AES key (16, 24 or 32 bytes), which is then used to encrypt the actual plaintext message of almost any size. It is also possible to use e.g. RSA-KEM to establish a particular key rather than to encrypt one directly. Using RSA and AES together is called a hybrid cryptosystem as it both comprises of asymmetric and symmetric encryption.

使用 textbook / raw RSA进行练习,则可以加密任何类型的数字,只要它小于模数即可。现在,如何将消息分成足够小的部分,以及如何将数字转换为数字,完全取决于您-只要您可以逆转该过程,就可以了。

If you want to use textbook / raw RSA for practice then you can encrypt any kind of number, as long as it is smaller than the modulus. Now how you split your message into small enough components and how you convert to / from a number is entirely up to you - as long as you can reverse the process, obviously.

通常,您只需将几个8位拉丁字符组合在一起,例如4,将它们转换为32位无符号数字,然后在RSA计算中使用该数字。然后再取下4个,依此类推。可以在需要的地方加空格。

Usually you just take a few 8-bit Latin characters together, say 4, convert them to a 32 bit unsigned number, and use that number in your RSA calculations. Then you take the next 4 etc. You can pad with spaces where required.

显然,如果您的数字太小,您会遇到直接的问题(1为幂)毕竟,即使有很大的密钥,公共指数仍为1);为了保护RSA,需要 一种安全的填充方法。同样,通常用于实施RSA的密钥大小过小(小于512位),无法提供任何类型的安全性。

Kind of obviously you run into immediate problems if your number is too small (1 to the power of the public exponent is still 1, after all, not very secure even with a large key size); to secure RSA a secure padding method is required. Similarly, usually the key sizes that are used to practice RSA are too small (smaller than 512 bits) to provide any kind of security.

这篇关于RSA在加密句子时如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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