编程资料集中营
 | 网站首页 | 文章中心 | 编程资料2 | 软件下载 | BT下载 | 八卦星闻 | 音乐在线 | 在线游戏 | 免费电影 | 给我留言 | 
一个简单的RSA算法实现JAVA源代码-Java技术
          ★★★
【字体:
一个简单的RSA算法实现JAVA源代码-Java技术 进入问吧

本站地址:http://www.bajiao123.com

作者:admin    文章来源:网络    点击数:    更新时间:2006-12-27    
来源:WEB开发资源联盟(http://cnpoint.com/)
作者:phpcms
原文:一个简单的RSA算法实现JAVA源代码(http://cnpoint.com/framwwork/2006/1027/content_4515.htm)

filename:RSA.java

/*
* Created on Mar 3, 2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/

import java.math.BigInteger;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.FileWriter;
import java.io.FileReader;
import java.io.BufferedReader;
import java.util.StringTokenizer;

/**
* @author Steve
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class RSA {
   
    /**
     * BigInteger.ZERO
     */
    private static final BigInteger ZERO = BigInteger.ZERO;
   
    /**
     * BigInteger.ONE
     */
    private static final BigInteger ONE = BigInteger.ONE;
   
    /**
     * Pseudo BigInteger.TWO
     */
    private static final BigInteger TWO = new BigInteger("2");
   
    private BigInteger myKey;
   
    private BigInteger myMod;
   
    private int blockSize;
   
    public RSA (BigInteger key, BigInteger n, int b) {
        myKey = key;
        myMod = n;
        blockSize = b;
    }
   
    public void encodeFile (String filename) {
        byte[] bytes = new byte[blockSize / 8 + 1];
        byte[] temp;
        int tempLen;
        InputStream is = null;
        FileWriter writer = null;
        try {
             is = new FileInputStream(filename);
             writer = new FileWriter(filename + ".enc");
        }
        catch (FileNotFoundException e1){
            System.out.println("File not found: " + filename);
        }
        catch (IOException e1){
            System.out.println("File not found: " + filename + ".enc");
        }
       
        /**
         * Write encoded message to 'filename'.enc
         */
        try {
            while ((tempLen = is.read(bytes, 1, blockSize / 8)) > 0) {
                for (int i = tempLen + 1; i < bytes.length; ++i) {
                    bytes[i] = 0;
                }
                writer.write(encodeDecode(new BigInteger(bytes)) + " ");
            }
        }
        catch (IOException e1) {
      &nbs

[1] [2] [3] [4] 下一页

   

进入问吧

一个简单的RSA算法实现JAVA源代码-Java技术

本站地址:http://www.bajiao123.com

文章录入:admin    责任编辑:admin 
高级搜索
编程资料集中营