久久久久久久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 文件,我復(fù)制這些文件并粘貼到當前目錄并編寫java代碼如下,當我運行它時沒有執(zhí)行加密或解密,請看看這個并告訴我哪里出錯了

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);
    }

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

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

相關(guān)文檔推薦

Java Remove Duplicates from an Array?(Java從數(shù)組中刪除重復(fù)項?)
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(如何修復(fù)調(diào)用失敗來自服務(wù)器的意外響應(yīng):在 Android 工作室中未經(jīng)授權(quán))
How to add GitLab repository in Eclipse?(如何在 Eclipse 中添加 GitLab 存儲庫?)
AES encryption, got extra trash characters in decrypted file(AES 加密,解密文件中有多余的垃圾字符)
主站蜘蛛池模板: 一区视频 | 欧美一级在线视频 | 亚洲精品中文字幕av | 久久久一区二区 | 91精品国产日韩91久久久久久 | 99福利视频 | 九九精品在线 | 欧美一区二区三区小说 | 一区二区视频在线 | 在线观看免费黄色片 | 成年人在线播放 | 国产美女永久免费无遮挡 | 可以免费看的毛片 | 91久久久www播放日本观看 | 一区二区三区视频在线观看 | 黄色在线免费观看 | 伊人免费观看视频 | 日韩α片 | 狠狠的干 | 日韩av高清 | 麻豆视频在线看 | 欧美在线观看一区 | 欧美男人天堂 | 国产精品91久久久久久 | 91日韩在线 | 亚洲国产精品日本 | 亚洲一区视频在线 | 亚洲高清视频在线观看 | 欧美日韩国产一区二区三区 | 国产午夜精品一区二区三区四区 | 国产激情一区二区三区 | 999久久久 | 色呦呦在线 | 老司机精品福利视频 | 欧美一区二区三区在线看 | 色婷婷综合久久久中字幕精品久久 | 国产高清视频在线播放 | 国产日韩一区二区三免费高清 | 神马福利 | 日韩精品一区二区三区中文字幕 | 欧美一区二区在线观看 |