📄 enc_rsa.java
字号:
import java.security.interfaces.*;
import java.math.*;
import java.io.*;
//类声明,用到的大数均由JAVA类库提供
public class Enc_RSA{
public static void main(String args[]) throws Exception{
String s="Hello World!";
FileInputStream f=new FileInputStream("Skey_RSA_pub.txt");
ObjectInputStream b=new ObjectInputStream(f);
RSAPublicKey pbk=(RSAPublicKey)b.readObject( );//得到RSA公钥描述结构类
BigInteger e=pbk.getPublicExponent();//得到公钥
BigInteger n=pbk.getModulus();//得到公共模
//BigInteger n = new BigInteger("65531".getBytes());//打算用自己的公钥
//BigInteger e = new BigInteger("17".getBytes());
System.out.println("e= "+e);
System.out.println("n= "+n);
byte ptext[]=s.getBytes();//将明文转化成UTF8格式
BigInteger m=new BigInteger(ptext);
System.out.println("m= "+m);
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.txt")));
out.write(cs,0,cs.length( ));
out.close( );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -