我想将我的密钥库对象从我的服务器传输到客户端应用程序:
我正在做以下事情:
response.reset();
response.setBufferSize(10240);
response.setContentType(contentType);
response.setHeader("Content-Length", String.valueOf(keystoreFile.length()));
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
BufferedInputStream input = null;
BufferedOutputStream output = null;
try{
input = new BufferedInputStream(new FileInputStream(keystoreFile), DEFAULT_BUFFER_SIZE);
output = new BufferedOutputStream(response.getOutputStream(), DEFAULT_BUFFER_SIZE);
output.write(KeyStoreUtil.getFileByteArray(input));
}finally{
input.close();
output.close();
}
但是文件在客户端损坏并且在获取密钥库时收到错误:
java.io.EOFException
at java.io.DataInputStream.readInt(DataInputStream.ja
at com.sun.crypto.provider.JceKeyStore.engineLoad(Jce
at java.security.KeyStore.load(KeyStore.java:1214)
实际上我看到的是,文件正在创建: 如果我从命令提示符运行命令:
keytool -list -storetype jceks -keystore aeskeystore.jck
Enter keystore password:
我收到错误:
keytool error: java.io.IOException: Keystore was tampered with, or password was incorrect
getFileByteArray如下:
public static byte[] getFileByteArray(InputStream fileInputStream) {
if (fileInputStream != null) {
int readLine = 0;
byte[] data = new byte[16384];
ByteArrayOutputStream fileBuffer = new ByteArrayOutputStream();
try {
while ((readLine = fileInputStream.read(data, 0, data.length)) != -1) {
fileBuffer.write(data, 0, readLine);
}
return fileBuffer.toByteArray();
} catch (IOException e) {
logger.error("Error occurred while reading keyfile::::"
+ e.getMessage());
}
}
return null;
}