【发布时间】:2015-06-13 06:32:18
【问题描述】:
我正在使用 RSA 算法对大小超过 rsa 密钥大小的文件进行加密和解密。
在下面的加密代码中,我以块方式读取文件内容并转换为密文。块大小为 32 字节。
FileInputStream fin1 = new FileInputStream(genfile);
FileOutputStream fout = new FileOutputStream(seedcipher);
byte[] block = new byte[32];
int i;
while ((i = fin1.read(block)) != -1)
{
byte[] inputfile= cipher.doFinal(block);
fout.write(inputfile);
}
fin1.close();
在解密部分,在我提到块大小为 128 字节的代码中进行了相同的逐块解密
FileInputStream fin1 = new FileInputStream(encryptedfile);
FileOutputStream fout = new FileOutputStream(seedcipher);
DataInputStream dos =new DataInputStream(fin1);
DataOutputStream dosnew =new DataOutputStream(fout);
byte[] block = new byte[128];
int i;
while ((i = fin1.read(block)) != -1)
{
byte[] inputfile= cipher.doFinal(block);
fout.write(inputfile);
}
输入文件大小为 81.3 kB,文件包含
0 1 2 3 4.....29000文件解密后,输出包含一些不相关的额外值。为什么结果中有额外的数据?
【问题讨论】:
-
额外的值在哪里?它们只是在文件的末尾吗?
-
是的,额外的值是输出文件的结尾。
-
没有人使用 RSA 进行直接数据加密,每个人都使用混合加密,因为 RSA 太慢了。使用 AES 加密文件,使用 RSA 加密使用的 AES 密钥。
-
什么是“在解密部分,在我提到块大小为 128 字节的代码中进行相同的块级解密”应该是什么意思?还是英文吗?
-
在这种情况下,祝你的项目好运。我确实希望,当你交出它的时候,你也能礼貌地向你的导师提一下,你在现实世界中永远不会做这种傻事。谁知道呢,这甚至可能是你应该从中吸取的教训。
标签: java encryption rsa public-key-encryption