迅软手动解密文件夹,有几个文件解密报错解决方法

1. 对文件夹进行解密,文件夹里面有几个文件解密报错,如下图所示

 解决: 我们找到报错的文件,复制一份,手动解密 ,发现可以正常解密,找到报错的文件右键属性,发现文件是只读,如下图所示

 终上所述:该问题不是加密导致的文件,是因为文件设置了只读,所以解密会报错,把文件属性只读勾选去掉问题解决。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的示例代码,实现了文件夹中所有文件加密解密,并输出了运行时间: ``` import java.io.*; import java.security.*; import javax.crypto.*; import javax.crypto.spec.*; public class FileEncryptor { private static final int BUFFER_SIZE = 1024; public static void main(String[] args) throws Exception { String folderPath = "C:/MyFolder/"; // 文件夹路径 String password = "MyPassword"; // 加密密码 long startTime = System.currentTimeMillis(); encryptFolder(folderPath, password); long endTime = System.currentTimeMillis(); System.out.println("Encryption time: " + (endTime - startTime) + "ms"); startTime = System.currentTimeMillis(); decryptFolder(folderPath, password); endTime = System.currentTimeMillis(); System.out.println("Decryption time: " + (endTime - startTime) + "ms"); } public static void encryptFolder(String folderPath, String password) throws Exception { File folder = new File(folderPath); if (!folder.isDirectory()) { throw new Exception("Invalid folder path"); } for (File file : folder.listFiles()) { if (file.isFile()) { encryptFile(file.getAbsolutePath(), password); } } } public static void decryptFolder(String folderPath, String password) throws Exception { File folder = new File(folderPath); if (!folder.isDirectory()) { throw new Exception("Invalid folder path"); } for (File file : folder.listFiles()) { if (file.isFile()) { decryptFile(file.getAbsolutePath(), password); } } } public static void encryptFile(String filePath, String password) throws Exception { File inputFile = new File(filePath); File encryptedFile = new File(filePath + ".encrypted"); KeyGenerator keyGenerator = KeyGenerator.getInstance("AES"); SecureRandom secureRandom = new SecureRandom(password.getBytes()); keyGenerator.init(128, secureRandom); SecretKey secretKey = keyGenerator.generateKey(); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, secretKey); IvParameterSpec ivParameterSpec = cipher.getParameters().getParameterSpec(IvParameterSpec.class); try (FileInputStream inputStream = new FileInputStream(inputFile); FileOutputStream outputStream = new FileOutputStream(encryptedFile)) { outputStream.write(ivParameterSpec.getIV()); byte[] buffer = new byte[BUFFER_SIZE]; int bytesRead; while ((bytesRead = inputStream.read(buffer)) != -1) { byte[] encryptedBytes = cipher.update(buffer, 0, bytesRead); outputStream.write(encryptedBytes); } byte[] encryptedBytes = cipher.doFinal(); outputStream.write(encryptedBytes); } inputFile.delete(); } public static void decryptFile(String filePath, String password) throws Exception { File encryptedFile = new File(filePath); if (!encryptedFile.isFile()) { throw new Exception("Invalid file path"); } File decryptedFile = new File(filePath.substring(0, filePath.lastIndexOf('.'))); try (FileInputStream inputStream = new FileInputStream(encryptedFile); FileOutputStream outputStream = new FileOutputStream(decryptedFile)) { byte[] ivBytes = new byte[16]; inputStream.read(ivBytes); IvParameterSpec ivParameterSpec = new IvParameterSpec(ivBytes); KeyGenerator keyGenerator = KeyGenerator.getInstance("AES"); SecureRandom secureRandom = new SecureRandom(password.getBytes()); keyGenerator.init(128, secureRandom); SecretKey secretKey = keyGenerator.generateKey(); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, secretKey, ivParameterSpec); byte[] buffer = new byte[BUFFER_SIZE]; int bytesRead; while ((bytesRead = inputStream.read(buffer)) != -1) { byte[] decryptedBytes = cipher.update(buffer, 0, bytesRead); outputStream.write(decryptedBytes); } byte[] decryptedBytes = cipher.doFinal(); outputStream.write(decryptedBytes); } encryptedFile.delete(); } } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值