android - 如何使用 iOS 和 Android 的密码 (AES) 压缩文件?

标签 android ios passwords zip

<分区>

是否有能够使用 AES 加密压缩带密码文件的库?

为 iOS 找到这个:https://github.com/gianlucabertani/Objective-Zip

最佳答案

更新:

更新参数中的密码设置和压缩文件创建方法。

您可以使用 Zip4j 库 http://www.lingala.net/zip4j/download.php

如果你想要 AES 加密,你也可以使用以下代码

// Initiate ZipFile object with the path/name of the zip file.
            ZipFile zipFile = new ZipFile("c:\\ZipTest\\AddFilesWithAESZipEncryption.zip");

// Build the list of files to be added in the array list
            // Objects of type File have to be added to the ArrayList
            ArrayList filesToAdd = new ArrayList();
            filesToAdd.add(new File("c:\\ZipTest\\sample.txt"));
            filesToAdd.add(new File("c:\\ZipTest\\myvideo.avi"));
            filesToAdd.add(new File("c:\\ZipTest\\mysong.mp3"));

            // Initiate Zip Parameters which define various properties
            ZipParameters parameters = new ZipParameters();
            parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE); // set compression method to deflate compression

 //DEFLATE_LEVEL_FASTEST     - Lowest compression level but higher speed of compression
            //DEFLATE_LEVEL_FAST        - Low compression level but higher speed of compression
            //DEFLATE_LEVEL_NORMAL  - Optimal balance between compression level/speed
            //DEFLATE_LEVEL_MAXIMUM     - High compression level with a compromise of speed
            //DEFLATE_LEVEL_ULTRA       - Highest compression level but low speed
            parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);

            //Set the encryption flag to true
            parameters.setEncryptFiles(true);

            //Set the encryption method to AES Zip Encryption
            parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES);

            //AES_STRENGTH_128 - For both encryption and decryption
            //AES_STRENGTH_192 - For decryption only
            //AES_STRENGTH_256 - For both encryption and decryption
            //Key strength 192 cannot be used for encryption. But if a zip file already has a
            //file encrypted with key strength of 192, then Zip4j can decrypt this file
            parameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256);

            //set password
            parameters.setPassword("your password here");

// Now add files to the zip file
            // Note: To add a single file, the method addFile can be used
            // Note: If the zip file already exists and if this zip file is a split file
            // then this method throws an exception as Zip Format Specification does not 
            // allow updating split zip files
            zipFile.addFiles(filesToAdd, parameters);

setEncryptionMethod() 将类型设置为您想要的加密。 setAesKeyStrength() 设置加密算法的强度。

关于android - 如何使用 iOS 和 Android 的密码 (AES) 压缩文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33205999/

相关文章:

android - android :layout_alignParentTop and android:layout_alignParentStart之间的区别

iphone - 使用 NSPredicate iOS 在具有 NSArray 和 NSString 的 NSArray 中查找值

iPhone/仪器 : what's about the "malloc" entries in object summary?

ruby-on-rails - Rails http_basic_authenticate_with

android - 在 Android/iOS 上获取默认设备方向(横向或纵向)

java - 关于 didRangeBeaconsInRegion

android - 为什么Gradle需要这么频繁的上网?

ios - 如何在 IOS 7 中实现 UIViewController 与前后过渡的导航?

unicode - I18n 和非 US-ASCII、Latin1 或 Win1252 的密码

python - 我的谷歌应用引擎部署的源代码安全吗?