⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dec_rsa.java

📁 RSA加密算法java代码
💻 JAVA
字号:
package src;
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{
	RSAPrivateKey prk;
	
	public Dec_RSA(String RSAPrivateKeyFileName) throws Exception
	{
		 FileInputStream f=new FileInputStream(RSAPrivateKeyFileName);
	     ObjectInputStream b=new ObjectInputStream(f);
	     prk=(RSAPrivateKey)b.readObject( );
	     b.close();
	     f.close();
	     
	}
	public String deCrypt(String Msg) throws Exception
	{
		BigInteger c=new BigInteger(Msg);
		BigInteger d=prk.getPrivateExponent();
        BigInteger n=prk.getModulus();
        BigInteger m=c.modPow(d,n);
        return new String(m.toByteArray(),"utf8");
	}

   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 ");
        System.out.println(new String(mt,"utf8"));

     
   }
   


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -