日期:2014-05-20  浏览次数:20703 次

Java如何读取文件?
源文件如下,小弟没有学过Java,下面是一段JAVA用RSA加密字符串的程序,
命令行的形式是Java   PublicExample   ABCDEFG
哪位大哥能把它改成,读取一个公钥,加密一个txt文件,并指定输出私钥路径,及加密后txt的路径
如命令行的形式是Java   PublicExample   c:\未加密.txt   c:\公钥.txt   c:\生成私钥.txt   c:\生成加密.txt
/*
  Public   Key   cryptography   using   the   RSA   algorithm.
*/

import   java.security.*;
import   javax.crypto.*;
import   org.bouncycastle.jce.provider.JCERSACipher;
import   java.io.*;
import   java.io.FileReader;
import   java.io.File;
import   java.io.FileWriter;


public   class   PublicExample   {

        public   static   void   main   (String[]   args)   throws   Exception   {
                //
                //   Check   args   and   get   plaintext
                if   (args.length   !=1)   {
                        System.err.println( "Usage:   java   PublicExample   text ");
                        System.exit(1);
                }
                byte[]   plainText   =   args[0].getBytes( "UTF8 ");
                //
                //   Generate   an   RSA   key
                System.out.println(   "\nStart   generating   RSA   key "   );
                KeyPairGenerator   keyGen   =   KeyPairGenerator.getInstance( "RSA ",   new   org.bouncycastle.jce.provider.BouncyCastleProvider());
                keyGen.initialize(1024);
                KeyPair   key   =   keyGen.generateKeyPair();
                System.out.println(   "Finish   generating   RSA   key "   );
                //
                //   Creates   an   RSA   Cipher   object   (specifying   the   algorithm,   mode,   and   padding).
                //Cipher   cipher   =   Cipher.getInstance( "RSA/ECB/PKCS1Padding ");
                Cipher   cipher   =   Cipher.getInstance( "RSA ",   new   org.bouncycastle.jce.provider.BouncyCastleProvider());
                //
                //   Print   the   provider   information
                System.out.println(   "\n "   +   cipher.getProvider().getInfo()   );
                System.out.println(   "\nStart   encryption "   );
                //
                //   Initializes   the   Cipher   object.