我发现它只是需要的问题将文件的内容作为字节数组返回。加密类
改变类FileController:
@RequestMapping(value =“/uploadLobCrypt”,method = RequestMethod.POST)
public ResponseEntity fileCrypt(MultipartFile multiPartFile,MultipartHttpServletRequest request) throws IOException, InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, InvalidKeySpecException {
fileLobService.fileCrypt(multiPartFile, request);
return new ResponseEntity<String>("{}", HttpStatus.OK);
}
类FileLobService
public void fileCrypt(MultipartFile
multiPartFile,MultipartHttpServletRequest
request) throws IOException, InvalidKeyException, NoSuchAlgorithmException,
NoSuchPaddingException,IllegalBlockSizeException,
BadPaddingException,InvalidKeySpecException {
// ecriture clee public et public dans un path
String publicKeyPath = "C:\\OpenSSL-Win64\\bin\\public.der";
//String privateKeyPath = "C:\\OpenSSL-Win64\\bin\\private.pk8";
Iterator<String> itr = request.getFileNames();
String uploadedFile = itr.next();
MultipartFile file = request.getFile(uploadedFile);
String mimeType = file.getContentType();
String filename = file.getOriginalFilename();
byte[] bytes = file.getBytes();
Long size = file.getSize();
Cryptage cryptage = new Cryptage();
byte[] encryptedBytes = cryptage.encryptFile(bytes, publicKeyPath);
FileUpload fileUploaded = new FileUpload(filename, encryptedBytes, mimeType,size);
fileUploadRepository.saveAndFlush(fileUploaded);
}
注意:它对于大文件的小文件很有用,我们必须使用SHA-256消息摘要算法或更多