2 Star 0 Fork 0

Haisu_20165202/Team

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Enc_RSA.java 1.03 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 Enc_RSA {
public static void main(String args[]) throws Exception {
String s = "I love Java";
// 获取公钥及参数e,n
FileInputStream f = new FileInputStream("Skey_RSA_pub.dat");
ObjectInputStream b = new ObjectInputStream(f);
RSAPublicKey pbk = (RSAPublicKey) b.readObject();
BigInteger e = pbk.getPublicExponent();
BigInteger n = pbk.getModulus();
System.out.println("e= " + e);
System.out.println("n= " + n);
// 明文 m
byte ptext[] = s.getBytes("UTF8");
BigInteger m = new BigInteger(ptext);
// 计算密文c,打印
BigInteger c = m.modPow(e, n);
System.out.println("c= " + c);
// 保存密文
String cs = c.toString();
BufferedWriter out =
new BufferedWriter(new OutputStreamWriter(
new FileOutputStream("Enc_RSA.dat")));
out.write(cs, 0, cs.length());
out.close();
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/Haisu98/Team.git
git@gitee.com:Haisu98/Team.git
Haisu98
Team
Team
master

搜索帮助