RSA算法加解密 写出写出简单加解密过程给我

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/28 03:09:31
RSA算法加解密 写出写出简单加解密过程给我

RSA算法加解密 写出写出简单加解密过程给我
RSA算法加解密 写出写出简单加解密过程给我

RSA算法加解密 写出写出简单加解密过程给我
import java.security.*;
import java.security.interfaces.*;
import java.math.*;
import java.io.*;
public class Password_Test {
public static void main(String[] args) {
try {
new Password_Test();
Encryption_RSA();
} catch (Exception e) {
e.printStackTrace();
}
}
public Password_Test() throws Exception {// 构造方法 创建公钥和私钥
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");//生成实现RSA算法的KeyPairGenerator对象.
kpg.initialize(1024);// 初始化确定密钥的大小
KeyPair kp = kpg.genKeyPair();// 生成密钥对
PublicKey pbkey = kp.getPublic();// 创建公钥
PrivateKey prkey = kp.getPrivate();// 创建私钥
// 保存公钥
FileOutputStream file1 = new FileOutputStream("D:/temp/Skey_RSA_pub.dat");
ObjectOutputStream ob1 = new ObjectOutputStream(file1);//创建ObjectOutputStream对象
ob1.writeObject(pbkey); //将指定的对象写入 ObjectOutputStream.
// 保存私钥
FileOutputStream file2 = new FileOutputStream("D:/temp/Skey_RSA_priv.dat");
ObjectOutputStream ob2 = new ObjectOutputStream(file2);
ob2.writeObject(prkey);
}
public static void Encryption_RSA() throws Exception {
System.out.println("根据公钥生成密文:"+"\n");
String string = "I am a student";
// 获取公钥及参数e,n
FileInputStream f_in = new FileInputStream("D:/temp/Skey_RSA_pub.dat");
ObjectInputStream o_in = new ObjectInputStream(f_in);
RSAPublicKey pbk = (RSAPublicKey) o_in.readObject();
BigInteger e = pbk.getPublicExponent();//返回此公钥的指数
BigInteger n = pbk.getModulus();//返回此公钥的模
System.out.println("公钥的指数 e= " + e);
System.out.println("公钥的模 n= " + n);
// 明文 bit
byte bt[] = string.getBytes("UTF8");
BigInteger bit = new BigInteger(bt);
// 计算密文c,打印
BigInteger mi = bit.modPow(e, n);//生成密文
System.out.println("生成密文为: " + mi+"\n\n");//打印密文
// 保存密文
String save = mi.toString();
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream("D:/temp/Enc_RSA.dat")));
out.write(save, 0, save.length());
out.close();
Decrypt_RSA();
}
public static void Decrypt_RSA() throws Exception {
System.out.println("根据私钥破解密文:"+"\n");
// 读取密文
BufferedReader in = new BufferedReader(new InputStreamReader(
new FileInputStream("D:/temp/Enc_RSA.dat")));
String ctext = in.readLine();
BigInteger mi = new BigInteger(ctext);
// 读取私钥
FileInputStream f = new FileInputStream("D:/temp/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 jie = mi.modPow(d, n);//进行解密操作
System.out.println("m= " + jie); // 显示解密结果
byte[] mt = jie.toByteArray();
System.out.println("解密后的文本内容为: ");
for (int i = 0; i < mt.length; i++) {
System.out.print((char) mt[i]);
}
}
}

RSA算法加解密 写出写出简单加解密过程给我 RSA算法 用RSA算法 试给出m=student的加解密过程Eucliden算法 得出d RSA加密计算求出密文给定 P=3,Q=5,明文M=13要求用RSA加密算法求出密文C.并写出加密和解密算法的过程? RSA加密解密AB的过程 完成RSA算法,RSA加密 p=3,q=11,e=7,M=5;请写出求公钥和私钥的过程.1.请写出求公钥和私钥的过程.2.根据公钥和私钥,写出用RSA算法加密解密的式子. 简述RSA体制密钥的生成及其加密、解密算法. 在RSA密码体制中,已知P=3,Q=11,E=7,M=4,计算M加密的密文C是多少?将C解密后的结果是多少?要求写出加密过程和解密过程. 使用RSA公开密钥体制进行加密,若P=2,q=5,求公钥e,私钥d,给出明文m=2的加解密过程 求RSA加密解密算法,c++源代码知道公钥e和密钥d,如何进行加密解密编码 RSA算法中,设p=9,q=23,计算加密密钥和解密密钥(要求写出详细计算过程和必要的说明)明文m是怎么来的 是自己假设的还是特定的 比如这题 应该怎么假设 看看这个RSA算法以下为加密代码,帮忙做个解密代码,谢谢大师们了例子:已知密文:46256712,加密后:231218582262182134138现在求解密算法,也就是已知:231218582262182134138,求46256712,也就是求解密代码 RSA算法 问题请问一下关于RSA问题, p=11, p=19; e =7; 算出 d=103; 假如 要 发送100 这个信息,怎么 加密,收到 加密之后 怎么解密?谁能 给讲解一下这个 加密 解密过程? RSA算法中,素数p=7,q=11,加密密钥e=7,计算解密密钥d 假设需要加密的明文信息为m=14,选择:e=3,p=5,q=11,试说明使用RSA算法的加密和解密过程及结果? 使用素数 29 61 根据RSA算法生成密钥 写出完整过程 外星人解密 kasiski法的来源,历史,基本原理,加解密方法并举例说明 给出p、q、e、M,求公钥,私钥,并且利用RSA算法加密和解密?有人知道怎么做这样的一道题目吗,可以的话最好举例子说明,麻烦详细点,给出p、q、e、M,设计一个RSA算法,求公钥,私钥,并且利用RSA算法