📄 dec_rsa.java
字号:
/*
m:明文;
c:密文;
p,q:两个大素数
n=p*q;FI(n)=(p-1)(q-1);
加密密钥(私钥):e;
解密密钥(公钥):d;
d*e=1 mod FI(n)
加密过程:
c=m^e(mod n);
解密过程:
m=c^d(mod n);
*/
//加密过程
//引入相关头文件,主要是java.security包下的类和java.crpto下的类
import java.security.interfaces.*;
import java.math.*;
import java.io.*;
public class Dec_RSA{
public static void main(String args[]) throws Exception{
BufferedReader in=
new BufferedReader(new InputStreamReader(new FileInputStream("Enc_RSA.txt")));
String ctext=in.readLine();
BigInteger c=new BigInteger(ctext);
FileInputStream f=new FileInputStream("Skey_RSA_priv.txt");
ObjectInputStream b=new ObjectInputStream(f);
RSAPrivateKey prk=(RSAPrivateKey)b.readObject( );
BigInteger d=prk.getPrivateExponent();
BigInteger n=prk.getModulus();
//BigInteger n = new BigInteger("65531".getBytes());//打算用自己的私钥
//BigInteger d = new BigInteger("21905".getBytes());
System.out.println("d= "+d);
System.out.println("n= "+n);
BigInteger m=c.modPow(d,n);
System.out.println("m= "+m);
byte[] mt=m.toByteArray();
String test = new String(mt);
System.out.println("PlainText is " + test);
//////for(int i=0;i<mt.length;i++){
//// System.out.print(mt.toString());
//}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -