• <em id="6vhwh"><rt id="6vhwh"></rt></em>

    <style id="6vhwh"></style>

    <style id="6vhwh"></style>
    1. <style id="6vhwh"></style>
        <sub id="6vhwh"><p id="6vhwh"></p></sub>
        <p id="6vhwh"></p>
          1. 国产亚洲欧洲av综合一区二区三区 ,色爱综合另类图片av,亚洲av免费成人在线,久久热在线视频精品视频,成在人线av无码免费,国产精品一区二区久久毛片,亚洲精品成人片在线观看精品字幕 ,久久亚洲精品成人av秋霞

            另一個程序正在使用此文件(另一個程序正在使用此文件怎么辦)

            更新時間:2023-03-01 17:26:51 閱讀: 評論:0

            原因:最近在用Sqlite存儲數(shù)據(jù),因涉及數(shù)據(jù)安全,所以需要數(shù)據(jù)庫加密,Sqlite庫默認(rèn)不帶加密功能 目前已知的對 SQLite 加密的工具主要有「[SQLite Encryption Extension (SEE)]、[SQLiteEncrypt]、[SQLiteCrypt]、[SQLCipher],但是這里面僅有 SQLCipher 有免費版本。 所以自己有個方案,針對Sqlite無法就是限制不能直接查看,那就對文件進(jìn)行加密,需要連接的時候進(jìn)行文件解密就可以了,如果大神有更好的解決方案,請告知,謝謝!

            package com.ts.tools;

            import cn.hutool.core.io.FileUtil;

            import cn.hutool.core.io.IoUtil;

            import cn.hutool.crypto.symmetric.SymmetricAlgorithm;

            import cn.hutool.crypto.symmetric.SymmetricCrypto;

            import java.io.*;

            /** 加密解密文件

            * @author xhc

            * @version 1.0.0

            * @date 2022-10-31

            */

            public class FileEnDe {

            public static void main(String[] args) {

            try {

            //加密密碼

            String key="abcdefghijklmnop";

            //FileEnDe.encryptFile("D:/test.db",key,true);

            //FileEnDe.decryptFile("D:/test.db",key);

            System.out.println(FileEnDe.isLocked("D:/sysDb.db"));

            } catch (Exception e) {

            throw new RuntimeException(e);

            }

            }

            /**

            * 加密db文件(理論可以加密任何文件)

            * @param filePath 文件路徑

            * @param key16 加密密碼(必須16位)

            * @return boolean

            * @throws Exception

            */

            public static boolean encryptFile(String filePath,String key16,boolean isReadOnly){

            FileOutputStream fos =null;

            boolean bFlag=fal;

            try {

            if(FileUtil.exist(filePath)) {

            byte[] key = key16.getBytes();

            //取文件名稱含后綴

            String fileName=FileUtil.getName(filePath);

            //加密文件

            SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, key);

            FileInputStream fis = new FileInputStream(filePath);

            String newFilePath=filePath+"_e";

            fos=new FileOutputStream(newFilePath);

            aes.encrypt(fis, fos, true);

            fos.clo();

            //刪除源文件,注意如果文件被使用會報:另一個程序正在使用此文件,進(jìn)程無法訪問

            boolean isDel=FileUtil.del(filePath);

            if(isDel){

            //重命名加密文件為源文件

            FileUtil.rename(new File(newFilePath),fileName,true);

            //設(shè)置只讀文件

            if(isReadOnly) {

            File f=new File(filePath);

            f.tReadOnly();

            }

            }

            bFlag=true;

            }el{

            throw new RuntimeException(filePath+" 文件不存在!");

            }

            } catch (Exception e) {

            throw new RuntimeException(e);

            } finally {

            IoUtil.clo(fos);

            }

            return bFlag;

            }

            /**

            * 解密Db庫

            * @param filePath 文件路徑

            * @param key16 加密密碼(必須16位)

            * @return boolean

            * @throws Exception

            */

            public static boolean decryptFile(String filePath,String key16){

            boolean bFlag=fal;

            FileOutputStream fos =null;

            try {

            if(FileUtil.exist(filePath)) {

            byte[] key = key16.getBytes();

            //取文件名稱含后綴

            String fileName=FileUtil.getName(filePath);

            //解密文件

            SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, key);

            FileInputStream fis = new FileInputStream(filePath);

            String newFilePath=filePath+"_d";

            fos = new FileOutputStream(newFilePath);

            aes.decrypt(fis, fos, true);

            //注意,解密之后 fos 并未關(guān)閉,請先關(guān)閉

            fos.clo();

            //刪除源文件,注意如果文件被使用會報:另一個程序正在使用此文件,進(jìn)程無法訪問

            boolean isDel=FileUtil.del(filePath);

            if(isDel){

            //重命名加密文件為源文件

            FileUtil.rename(new File(newFilePath),fileName,true);

            }

            bFlag=true;

            }el{

            throw new RuntimeException(filePath+" 文件不存在!");

            }

            } catch (FileNotFoundException e) {

            throw new RuntimeException(filePath+" 文件不存在!");

            }catch (Exception e){

            throw new RuntimeException(e);

            }finally {

            IoUtil.clo(fos);

            }

            return bFlag;

            }

            /**

            * 文件是否占用(采用重命名的方式)

            * @param filePath 文件路徑

            * @return boolean

            */

            public static boolean isLocked(String filePath){

            boolean bFlag=fal;

            String newFileName="";

            String fileName="";

            try {

            if(FileUtil.exist(filePath)) {

            // 采用重命名的方式,如果占用無法修改文件名稱,如果未占用修改新的文件名稱后再修改回來

            fileName = FileUtil.getName(filePath);

            newFileName = fileName + "_n";

            FileUtil.rename(new File(filePath), newFileName, true);

            }

            } catch (Exception e) {

            bFlag=true;

            }finally {

            //如果未占用修改新的文件名稱后再修改回來

            if(!bFlag) {

            FileUtil.rename(new File(filePath+"_n"), fileName, true);

            }

            }

            return bFlag;

            }

            }

            本文發(fā)布于:2023-02-28 20:13:00,感謝您對本站的認(rèn)可!

            本文鏈接:http://m.newhan.cn/zhishi/a/167766281178822.html

            版權(quán)聲明:本站內(nèi)容均來自互聯(lián)網(wǎng),僅供演示用,請勿用于商業(yè)和其他非法用途。如果侵犯了您的權(quán)益請與我們聯(lián)系,我們將在24小時內(nèi)刪除。

            本文word下載地址:另一個程序正在使用此文件(另一個程序正在使用此文件怎么辦).doc

            本文 PDF 下載地址:另一個程序正在使用此文件(另一個程序正在使用此文件怎么辦).pdf

            標(biāo)簽:文件   程序
            相關(guān)文章
            留言與評論(共有 0 條評論)
               
            驗證碼:
            Copyright ?2019-2022 Comsenz Inc.Powered by ? 實用文體寫作網(wǎng)旗下知識大全大全欄目是一個全百科類寶庫! 優(yōu)秀范文|法律文書|專利查詢|
            主站蜘蛛池模板: 忘忧草www日本韩国| 精选国产av精选一区二区三区| 日本高清免费毛片久久| www亚洲精品| 正在播放国产剧情亂倫| 亚洲欧美日韩精品久久| 99久久无码私人网站| 亚洲第一色网站| 日韩精品一区二区亚洲av | 国产精品人成视频免费999| 国产精品老熟女乱一区二区| 日区中文字幕一区二区| 日韩中文字幕高清有码| 蜜桃臀无码AV在线观看| 亚洲精品va| 大地资源免费视频观看| 中文日韩亚洲欧美字幕| 亚洲av高清一区二区三| 性视频一区| 亚洲色大成网站www在线| 免费夜色污私人影院在线观看| 人人妻人人澡人人爽| 国产成AV人片在线观看天堂无码 | 亚洲爆乳大丰满无码专区| 熟女国产精品一区二区三| 9丨精品国产高清自在线看| 亚洲欧美激情在线一区| 亚洲色大成网站WWW久久| 亚洲欧美综合中文| 精品一区二区三区四区色 | 中文日产幕无线码一区中文| 18禁成人免费无码网站| 亚洲av日韩av无码尤物| 亚洲国产精品一区在线看| 91久久国产热精品免费| 色老头在线一区二区三区| 国产一区二区不卡在线| 亚洲国产精品日韩av专区| 国产精品一线二线三线区| 思思热在线视频精品| 污污污污污污WWW网站免费|