简体   繁体   English

RSA使用openssl库加密500字节的数据

[英]RSA to encrypt 500 bytes of data using openssl library

I am using RSA algorithm for shared key encryption/decryption.I am using open ssl libraries and c language.RSA_size() returns 256bytes.the key(data to enrypt) size is more than 256bytes but less than 500 bytes.The RSA keysize used for encryption is 1024.keypair is generated using openssl library. 我正在使用RSA算法进行共享密钥加密/解密。我正在使用开放的ssl库和c语言.RSA_size()返回256bytes.key(要加密的数据)大小大于256bytes但小于500字节。使用的RSA keysize用于加密的是1024.keypair是使用openssl库生成的。 If data to encrypt is less than or equals to 245 bytes the encryption works fine(because of padding).Otherwise i have to break the data(not sure it is ok as iam trying to exchange shared key)Is there any other way to increase RSA_size.my code doesn't call RAND_seed()(not sure what argment to pass) before calling rsa_public_encrypt. 如果要加密的数据小于或等于245字节,则加密工作正常(由于填充)。否则我必须中断数据(不确定是否可以正常运行,因为我试图交换共享密钥)是否有其他方法可以增加RSA_size.my代码在调用rsa_public_encrypt之前不会调用RAND_seed()(不确定要传递的参数)。 Any help is appreciated. 任何帮助表示赞赏。

You can either break your data into chunks, or use the "seal"/"open" OpenSSL functions. 您可以将数据分成多个块,也可以使用“密封” /“打开” OpenSSL函数。

Essentially what they do is generate a random set of keys, encrypt the keys using the public key and then use those keys to encrypt whatever you want. 本质上,它们的作用是生成一组随机密钥,使用公共密钥对密钥进行加密,然后使用这些密钥对所需内容进行加密。 That way you're not limited to specific sizes and decryption is not too slow (you only decrypt the random keys using RSA, the rest is done using symmetric encryption so it's a lot faster). 这样,您就不必局限于特定的大小,解密也不会太慢(您仅使用RSA解密随机密钥,其余的使用对称加密完成,因此速度要快得多)。

I suggest you have a look at EVP_SealInit and EVP_OpenInit . 我建议您看看EVP_SealInitEVP_OpenInit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM