小编Pra*_*Rai的帖子

在java中使用rsa加密和解密大文件

我使用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();
Run Code Online (Sandbox Code Playgroud)

在解密部分,在代码中完成相同的逐块解密,其中我已经提到块大小为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);
}
Run Code Online (Sandbox Code Playgroud)

输入文件大小为81.3 kB并且文件包含

0
1
2
3
4.....29000 

解密文件后,输出包含一些不相关的额外值.为什么结果中有额外的数据?

java encryption rsa public-key-encryption

3
推荐指数
1
解决办法
8412
查看次数

标签 统计

encryption ×1

java ×1

public-key-encryption ×1

rsa ×1