java定长加密_使⽤RSA(Java)加密长字符串我在使⽤
Java时遇到的RSA应⽤程序出现问题.
我必须从⽂件中读取⼀个字符串,对其进⾏加密,然后将加密的字符串保存在⼀个新⽂件中.
我的RSA密钥长度为1024位.
问题所在的代码部分如下:
readBytes = in.read(bytesToBeEncoded, 0, bytesToBeEncoded.length);
while(readBytes != -1){
encodedContent = ciph.update(bytesToBeEncoded, 0, readBytes);
out.write(encodedContent);
bytesToBeEncoded= new byte[(KEY_SIZE/8)-11];
readBytes = in.read(bytesToBeEncoded, 0, bytesToBeEncoded.length);
}
encodedContent = ciph.doFinal();
out.write(encodedContent);
变量定义如下:
byte[] bytesToBeEncoded = new byte[(KEY_SIZE/8)-11];
FileInputStream in = new FileInputStream(new File(file1));
FileOutputStream out = new FileOutputStream(new File(file2));
int readBytes;
关键是当我加密⼀个⼩于117字节的字符串时,它完美地⼯作(加密然后解密),但是当⼤⼩更⼤时,应⽤程序抛出此异常:
java加密方式有哪些抛出:
encodedContent = ciph.doFinal();
我不知道问题出在哪⾥以及我必须做什么.
谁能帮助我?谢谢.
抱歉我的英语.

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。