2 Star 0 Fork 0

Haisu_20165202/Team

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Dec_RSA.java 1.07 KB
一键复制 编辑 原始数据 按行查看 历史
Haisu_20165202 提交于 7年前 . RSA算法
import java.security.*;
import java.security.spec.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import javax.crypto.interfaces.*;
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.dat")));
String ctext = in.readLine();
BigInteger c = new BigInteger(ctext);
//读取私钥
FileInputStream f = new FileInputStream("Skey_RSA_priv.dat");
ObjectInputStream b = new ObjectInputStream(f);
RSAPrivateKey prk = (RSAPrivateKey) b.readObject();
BigInteger d = prk.getPrivateExponent();
//获取私钥参数及解密
BigInteger n = prk.getModulus();
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();
System.out.println("PlainText is ");
for (int i = 0; i < mt.length; i++) {
System.out.print((char) mt[i]);
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/Haisu98/Team.git
git@gitee.com:Haisu98/Team.git
Haisu98
Team
Team
master

搜索帮助