久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在 Java 中加密或解密文件?

How to Encrypt or Decrypt a File in Java?(如何在 Java 中加密或解密文件?)
本文介紹了如何在 Java 中加密或解密文件?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我想用 java 加密和解密一個文件,我讀過這個 url http://www-users.york.ac.uk/~mal503/lore/pkencryption.htm 我有兩個文件,即公共安全證書和私人安全證書文件和 private.pem 文件,我復制這些文件并粘貼到當前目錄并編寫java代碼如下,當我運行它時沒有執行加密或解密,請看看這個并告訴我哪里出錯了

I want to encrypt and decrypt a file in java, i had read this url http://www-users.york.ac.uk/~mal503/lore/pkencryption.htm and i got two files namely public Security certificate and private security certificate file and private.pem file, i copied these files and pasted in the current directory and worte java code as follows, when i run this no encryption or decryption is performed, pls see this and tell me where i went wrong

加密代碼

File ecryptfile=new File("encrypt data");
                File publickeydata=new File("/publickey");
                File encryptmyfile=new File("/sys_data.db");
                File copycontent =new File("Copy Data");
                secure.makeKey();
                secure.saveKey(ecryptfile, publickeydata);
                secure.encrypt(encryptmyfile, copycontent);

解密代碼

File ecryptfile=new File("encrypt data");
                File privateKeyFile=new File("/privatekey");
                File encryptmyfile=new File("/sys_data.db");
                File unencryptedFile =new File("unencryptedFile");
                try {
                                secure.loadKey(encryptmyfile, privateKeyFile);
                                secure.decrypt(encryptmyfile, unencryptedFile);
                        } catch (GeneralSecurityException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        }

推薦答案

你只是弄亂了你的文件.此代碼使用您鏈接的文章中描述的從 openssl 生成的 DER 文件工作:

You simply have muddled your files. This code works using the DER files generated from openssl as described in the article you linked:

    FileEncryption secure = new FileEncryption();

    // Encrypt code
    {
        File encryptFile = new File("encrypt.data");
        File publicKeyData = new File("public.der");
        File originalFile = new File("sys_data.db");
        File secureFile = new File("secure.data");

        // create AES key
        secure.makeKey();

        // save AES key using public key
        secure.saveKey(encryptFile, publicKeyData);

        // save original file securely 
        secure.encrypt(originalFile, secureFile);
    }

    // Decrypt code
    {
        File encryptFile = new File("encrypt.data");
        File privateKeyFile = new File("private.der");
        File secureFile = new File("secure.data");
        File unencryptedFile = new File("unencryptedFile");

        // load AES key
        secure.loadKey(encryptFile, privateKeyFile);

        // decrypt file
        secure.decrypt(secureFile, unencryptedFile);
    }

這篇關于如何在 Java 中加密或解密文件?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Java Remove Duplicates from an Array?(Java從數組中刪除重復項?)
egit plugin for Eclipse(Eclipse 的 egit 插件)
Gitlab cannot open git-upload-pack error(Gitlab 無法打開 git-upload-pack 錯誤)
How to fix Invocation failed Unexpected Response from Server: Unauthorized in Android studio(如何修復調用失敗來自服務器的意外響應:在 Android 工作室中未經授權)
How to add GitLab repository in Eclipse?(如何在 Eclipse 中添加 GitLab 存儲庫?)
AES encryption, got extra trash characters in decrypted file(AES 加密,解密文件中有多余的垃圾字符)
主站蜘蛛池模板: 亚洲黄色av | 麻豆一区 | 网色| 一区二区三区免费 | 91视视频在线观看入口直接观看 | 亚洲综合中文字幕在线观看 | 免费观看黄网站 | 亚洲综合在线一区 | 爱草在线 | 国产日韩精品视频 | 国产福利在线播放 | 成人黄色电影在线播放 | 一级黄色毛片免费 | 免费大黄视频 | 精品视频一区二区在线观看 | 99久久国产 | 成人免费视频网站在线观看 | 99色视频| 精品一区二区久久久久久久网站 | 夜夜夜操 | 伊人狠狠| 国产成人免费视频网站视频社区 | 天天天操天天天干 | 欧美视频在线播放 | 国产成人精品午夜视频免费 | 欧美视频在线看 | www.蜜桃av| 精品区一区二区 | 在线免费观看日本视频 | 欧美日韩国产高清 | 九九热精品视频 | 午夜精品久久久 | 亚洲一区二区三区在线视频 | 中文字幕 亚洲一区 | 国产在线成人 | 国产综合第一页 | 国产视频91在线 | 精品国产欧美日韩不卡在线观看 | 一级黄色毛片 | 国产精品久久久久久久毛片 | 久久欧美精品 |