⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 untitled1.java

📁 手机上进行RSA加密的算法
💻 JAVA
字号:
package rsa;

import java.io.*;
import java.util.*;
/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

public class Untitled1 {

  static public long startApp (byte[] args) {
    int i,j;
    boolean debug = true;
    long thetime;
    byte[] ebyte={(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
        (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
        (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
        (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x00, (byte)0x01};

    byte[] nbyte={(byte)0xbb, (byte)0x9d, (byte)0x02, (byte)0x79, (byte)0x70, (byte)0xa6, (byte)0xf6, (byte)0xcb, (byte)0x75, (byte)0xb0, (byte)0x49, (byte)0xba, (byte)0xb0, (byte)0x22, (byte)0x13, (byte)0xda, (byte)0x02, (byte)0x3e, (byte)0x31, (byte)0x96, (byte)0x1e, (byte)0xa5, (byte)0x9b, (byte)0xa8, (byte)0x36, (byte)0xc1, (byte)0x04, (byte)0xd2, (byte)0x98, (byte)0x9d, (byte)0xdf, (byte)0x29, (byte)0xa0, (byte)0xdb, (byte)0xcb, (byte)0x41, (byte)0xca, (byte)0x9f, (byte)0x0f, (byte)0x99,
        (byte)0x5f, (byte)0xb9, (byte)0xc7, (byte)0xa0, (byte)0x38, (byte)0x19, (byte)0x74, (byte)0xb2, (byte)0xcd, (byte)0x41, (byte)0xcc, (byte)0xcd, (byte)0xe2, (byte)0xa5, (byte)0xba, (byte)0xd3, (byte)0x63, (byte)0xaa, (byte)0x3a, (byte)0xcd, (byte)0x65, (byte)0x9c, (byte)0x65, (byte)0x95, (byte)0xca, (byte)0x7d, (byte)0x98, (byte)0xc4, (byte)0xcf, (byte)0x0b, (byte)0xa4, (byte)0x00, (byte)0x2b, (byte)0x21, (byte)0x33, (byte)0x15, (byte)0xd5, (byte)0xd8, (byte)0x14, (byte)0x73, (byte)0x15,
        (byte)0xc2, (byte)0x1c, (byte)0xab, (byte)0xe1, (byte)0xec, (byte)0xcb, (byte)0xeb, (byte)0x34, (byte)0x26, (byte)0xe1, (byte)0xdd, (byte)0xb2, (byte)0x60, (byte)0x35, (byte)0xda, (byte)0x33, (byte)0x85, (byte)0x28, (byte)0xfd, (byte)0xf4, (byte)0xb1, (byte)0xb0, (byte)0x90, (byte)0xc9, (byte)0x1a, (byte)0xe2, (byte)0x65, (byte)0xa5, (byte)0xf0, (byte)0x95, (byte)0x6f, (byte)0xb3, (byte)0xb3, (byte)0xcb, (byte)0x20, (byte)0x7c, (byte)0x87, (byte)0xc9, (byte)0x9e, (byte)0x4f, (byte)0xb5,
        (byte)0x72, (byte)0x81, (byte)0x15, (byte)0x03, (byte)0xc9, (byte)0xa1};

    // get the current time
    long st = (new Date()).getTime();


    BigInteger e = new BigInteger(ebyte);
    BigInteger n = new BigInteger(nbyte);

    // make the PublicKey
    PublicKey pk = new PublicKey(n,e);
    if (debug) System.out.println("Public exponent = "+pk.e());
    if (debug) System.out.println("Public modulus = "+pk.n());

      /*shortBA is the padding data of original data,
       padding standard : PKCS1*/
           byte[] shortBA = new byte[128];
           shortBA[0] = 0x00;
           shortBA[1] = 0x02;
           int startNum = 128-1-args.length;
           for (i=2; i<startNum; i++) {
                shortBA[i] = 0x11;
           }
           shortBA[startNum] = 0x00;
           startNum++;
          /*the original data which is need to be encrypted*/
          for(i=startNum,j=0;i<128;i++,j++)
             shortBA[i] = args[j];

   /*             for (i=0; i<128; i++) {
                  System.out.println("shortBA[" + i + "]=" + shortBA[i]);
                }*/
                System.out.println("shortBA="+shortBA);
               System.out.println(pk.encrypt(new BigInteger(shortBA)));

       // show duration
       thetime = ((new Date()).getTime()-st)/1000;
    if (debug) System.out.println("That took "+((new Date()).getTime()-st)/1000+" seconds");
      return thetime;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -