spring openssl mysql_springboot-如何使用openssl与spring boot / mySql和dropzone js-行业智能,新时代,新科技,新码农...

我发现它只是需要的问题将文件的内容作为字节数组返回。加密类

改变类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消息摘要算法或更多

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值