RSA算法Java实现

时间:2022-04-12 10:13:46
【文件属性】:

文件名称:RSA算法Java实现

文件大小:7KB

文件格式:ZIP

更新时间:2022-04-12 10:13:46

加密算法 RSA练习

public static void decrypt() throws Exception { // 读取密文 BufferedReader in = new BufferedReader( new InputStreamReader(new FileInputStream("encrypt.dat"))); String ctext = in.readLine(); BigInteger c = new BigInteger(ctext); // 读取私钥 FileInputStream f = new FileInputStream("privatekey.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); PrintWriter out =new PrintWriter("E:\\miwen.txt","UTF-8");


【文件预览】:
RSA
----privatekey.dat(894B)
----bin()
--------RSA.class(5KB)
----encrypt.dat(307B)
----.settings()
--------org.eclipse.jdt.core.prefs(598B)
----src()
--------RSA.java(4KB)
----.project(379B)
----pubkey.dat(419B)
----.classpath(301B)

网友评论