在SymmetricAlgorithm中调用加密数据之前如何获取输出数据大小 [英] How to get the output data size before call encrypt data in SymmetricAlgorithm

查看:116
本文介绍了在SymmetricAlgorithm中调用加密数据之前如何获取输出数据大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的

我发现.NET SymmetricAlgorithm类不支持对数据进行加密后再获取输出大小的函数,如java方法getoutputsize(int inputLen).在调用加密数据之前,我需要知道输出大小.在测试中,我找到了一个公式来计算 块大小.

I found the .NET SymmetricAlgorithm class not support a function to get the output size after encrypt data like java method getoutputsize(int inputLen) . I need know the out put size before call encrypt data. In my test, I found a formula to calculate the block size.  output size = (Int(plain-text size /IV Size) +1) * IV Size (all size in bytes) . For example, plain-text size is 100 bytes, block size is 128 bits = 16 bytes, the output size = (Int(100/16) + 1) * 16 = 112.  Is the formula is right for all SymmerticAlgorithm(AES, DES, RC2, TripleDES, Rijndael) ?

Karry

推荐答案

Karry,

否.

AES:结果长度与输入数据长度相同

AES: the result length is the same with the input data length

DES:结果长度与输入数据长度相同

DES: the result length is the same with the input data length

RC2:结果长度与输入数据长度相同

RC2: the result length is the same with the input data length

TripleDES:输出大小=(Int(纯文本大小/IV大小)+1)* IV大小

TripleDES: output size = (Int(plain-text size /IV Size) +1) * IV Size

Rijndael:结果长度与输入数据长度相同

Rijndael: the result length is the same with the input data length

getoutputsize不适用于加密数据: http ://docs.oracle.com/javase/1.5.0/docs/api/javax/crypto/Cipher.html#getOutputSize(int )

getoutputsize is not for the encrypted data:http://docs.oracle.com/javase/1.5.0/docs/api/javax/crypto/Cipher.html#getOutputSize(int)

下一个更新或doFinal调用的实际输出长度可能小于此方法返回的长度.

今天愉快.


这篇关于在SymmetricAlgorithm中调用加密数据之前如何获取输出数据大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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