[英]Encrypting flexible amount of data with GPGME
I'm currently writing a C++ application and would like to use GPGME for message signing, encryption and key management. 我目前正在编写一个C ++应用程序,并希望使用GPGME进行消息签名,加密和密钥管理。 I know I can encrypt data in this way:
我知道我可以用这种方式加密数据:
err = gpgme_op_encrypt(mContext, recipients,...);
if(err) {
// .. error handling
}
result = gpgme_op_encrypt_result(mContext);
if(result->invalid_recipients){
//error handling
}
nbytes = gpgme_data_seek(encrypted_text, 0, SEEK_SET);
if(nbytes == -1) {
//error handling
}
buffer = malloc(MAXLEN);
nbytes = gpgme_data_read(encrypted_text, buffer, MAXLEN);
But as one can see I would have to use MAXLEN as limit for reading the encrypted data in my buffer. 但是可以看到,我必须使用MAXLEN作为读取缓冲区中加密数据的限制。 Is there a way to determine how long my encrypted data result will be in advance (given the plaintex)?
有没有一种方法可以确定我的加密数据结果将提前多长时间(考虑到plaintex)? Or will I have to accept the static limit?
还是我必须接受静态限制?
I'm not familiar with this particular API but the gpgme_data_seek
and gpgme_data_read
call look like they may behave like read()
and seek()
from the file I/O system. 我对这个特定的API并不熟悉,但是
gpgme_data_seek
和gpgme_data_read
调用看起来就像它们在文件I / O系统中的read()
和seek()
。
(1) Simply allocate as much buffer as you can effort (lets say N). (1)简单分配尽可能多的缓冲区(让我们说N)。
(2) Call n=gpgme_data_read(...,N)
until N!=n
. (2)调用
n=gpgme_data_read(...,N)
直到N!=n
。
(3) Check for error conditions (my guess is n<0) (3)检查错误情况(我的猜测是n <0)
proceed until you have processed all data you are interested in. 继续进行,直到处理完所有您感兴趣的数据为止。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.