怎么读取java文件,Java怎么读取文件

当前位置:我的异常网» J2SE » Java怎么读取文件

Java怎么读取文件

www.myexceptions.net  网友分享于:2013-12-20  浏览:60次

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.

文章评论

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值