A problem has been encountered in the project, for security reasons, you need to package the file in binary data as a compressed file, and the compressed file has a password.
Go to Google to find some API, download to see the next, and figured out the following methods
First put the API:
<!--Https://mvnrepository.com/artifact/de.idyl/winzipaes - <Dependency> <groupId>De.idyl</groupId> <Artifactid>Winzipaes</Artifactid> <version>1.0.1</version> </Dependency>
After using the API code is very simple, a binary input stream plug in, and then output into a binary stream can be
Public Static byte[] Compressbytes (byte[] Bytes, string entryName, String PassWord) {Bytearrayoutputstream bout=NULL; Bytearrayinputstream bin=NULL; Try { //binary array output streambout =NewBytearrayoutputstream (); Bin=NewBytearrayinputstream (Bytes.clone ()); Aeszipfileencrypter Encrypter; Encrypter=NewAeszipfileencrypter (bout,NewAESENCRYPTERBC ()); Encrypter.add (EntryName, Bin, PassWord); Encrypter.close (); returnBout.tobytearray (); } Catch(Exception e) {logger.error ("", E); } finally{streamutils.closequietly (bout, bin); } return NULL; } Public Static voidMain (string[] args)throwsIOException {byte[] bytes = Streamutils.read (NewFile ("C:\\2.png")); Streamutils.write (compressbytesinmemory (bytes,"2.png", "123456"), NewFileOutputStream (NewFile ("C:\\2.zip"))); }
How to compress and encrypt zip in memory