zsh_root
2024-01-02 7b595546af704983dbafcd0d385c8768ddacefc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package zhuce;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.math.BigInteger;
import java.security.interfaces.RSAPrivateKey;
import java.util.Properties;
 
public class decrypt {
 
    @SuppressWarnings("resource")
    public String Execdecrypt() {
        // TODO 自动生成构造函数存根
        String s="";
        try{
            //读取密文
            //BufferedReader in=new BufferedReader(new InputStreamReader(new FileInputStream("RSAmi.dat")));
            //String ctext=in.readLine();
            Properties pro = new Properties();//该类主要用于读取Java的配置文件
            try {
                /**将信息包存在a.ini文件中store(OutputStream out, String comments) 将此Properties表中的
                 * 此属性列表(键和元素对)以适合使用load(InputStream)方法加载到Properties表的格式写入输出流。 
                 * 此Properties方法不会写出此Properties表的defaults表中的属性(如果有)。
                 * FileOutputStream(File file, boolean append)
                 * append参数为true时,数据从文件尾部写入;append参数为false时,数据覆盖原文件**/
 
                pro.store(new FileOutputStream("a.ini",true),null);
 
                //  可以从a.ini中通过Properties.get方法读取配置信息
                //load(InputStream)方法加载到Properties表的格式写入输出流
 
                pro.load(new FileInputStream("a.ini"));
 
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
 
            String ctext=String.valueOf(String.valueOf(pro.get("register")));
 
            BigInteger c=new BigInteger(ctext);
            //获取私钥
            FileInputStream f=new FileInputStream("RSAPrikey.dat");
            ObjectInputStream b=new ObjectInputStream(f);
            RSAPrivateKey prk=(RSAPrivateKey)b.readObject();
            //得到公钥的两个参数
            BigInteger d=prk.getPrivateExponent();
            BigInteger n=prk.getModulus();
            //System.out.println("解密的私钥的指数为:"+d);
            //System.out.println("解密私钥的模为:"+n);
            //解密处理
            BigInteger m=c.modPow(d, n);
            byte [] mt=m.toByteArray();
            //System.out.println("解密后的明文为:");
            for(int i=0;i<mt.length;i++){
//                System.out.print((char)mt[i]);
                s+=(char)mt[i];
            }
            //}
        }catch(Exception e){
            e.printStackTrace();
        }
        return s;
    }
 
}