How to compress and encrypt zip in memory

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.