现在写了个加密程序,AES似乎到了20M之后,就报java.lang.OutOfMemoryError: Java heap space异常 byteIn = new byte[(int) file.length()];
bis.read(byteIn);
outFile = FileHelper.renameFileToFixName(outFile, outFile.getName());
out=new FileOutputStream(outFile);
bos = new BufferedOutputStream(out);
Cipher cipher = initCipher(Cipher.ENCRYPT_MODE);
byteOut = cipher.doFinal(byteIn);
bos.write(byteOut);我不想要CiperInputStream 这样的类,因为当加密之后,密钥不同解密不报错。
请问如何实现大文件的加密,解密
bis.read(byteIn);
outFile = FileHelper.renameFileToFixName(outFile, outFile.getName());
out=new FileOutputStream(outFile);
bos = new BufferedOutputStream(out);
Cipher cipher = initCipher(Cipher.ENCRYPT_MODE);
byteOut = cipher.doFinal(byteIn);
bos.write(byteOut);我不想要CiperInputStream 这样的类,因为当加密之后,密钥不同解密不报错。
请问如何实现大文件的加密,解密
解决方案 »
- 帮我看一下那个路径有什么问题
- 【急】JNA 中vector转换问题
- 关于org.apache.commons.net.ftp.FTPClient的用法?????
- 错误invalid escape sequence ()valid ones are \b\f---------
- 请教一个方法,
- 为什么下面的程序还会有 Syntax error on token ":", * expected
- 小弟请教:多列值放入ArrayList或者hashmap的问题。
- ***7000分请教:将一段C代码转换成Java代码***
- 如何禁用JFrame的最大化Button,但是又可以resize?
- 请教JFC
- java 对象
- QQ 飞秋 动态显示刚登陆上的好友
bis.read(byteIn);膜拜
请问读20G的文件会怎么样
byte[] buf = new byte[800 * 1024];
int read;
long pos = 0;
bt.start();
byte[] key=password.getBytes("UTF-8");
Crypto c=new Crypto(key, key.length);
byte[] result;
while ((read = fis.read(buf)) > 0) {
result = deEncrypt(buf, read, c);
fos.write(result, 0, result.length);
pos+=read;
if (!bt.back(read)) {
break;
}
}
int blockSize = cipher.getBlockSize() * 1000;
int outputSize = cipher.getOutputSize(blockSize);
byte[] inBytes = new byte[blockSize];
byte[] outBytes = new byte[outputSize];
int inLength = 0;
boolean more = true;
while (more) {
inLength = in.read(inBytes);
if (inLength == blockSize) {
int outLength = cipher.update(inBytes, 0, blockSize, outBytes);
out.write(outBytes, 0, outLength);
} else {
more = false;
}
}
if (inLength > 0)
outBytes = cipher.doFinal(inBytes, 0, inLength);
else
outBytes = cipher.doFinal();
out.write(outBytes);