111,128
社区成员
发帖
与我相关
我的任务
分享
BigInteger Module = new BigInteger("module数据", 16);
BigInteger publicExponent = new BigInteger("exponent", 16);
RSAPublicKeySpec localRSAPublicKeySpec = new RSAPublicKeySpec(Module, publicExponent);
KeyFactory fac = java.security.KeyFactory.getInstance("RSA");
PublicKey pk = fac.generatePublic(localRSAPublicKeySpec);
String text = "123"; //明文
Cipher localCipher = Cipher.getInstance("RSA/ECB/NoPadding");
localCipher.init(1, pk);
byte[] arr = localCipher.doFinal(text.getBytes()); //生成的密文
貌似只有这自带的了using System;
using System.Text;
using System.Security.Cryptography;
namespace RSA算法
{
class Program
{
static void Main(string[] args)
{
string s = "helloworld123467";
UnicodeEncoding ue = new UnicodeEncoding();
byte[] b1 = ue.GetBytes(s);
byte[] b2;
byte[] b3;
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
b2 = rsa.Encrypt(b1, true);//加密
Console.WriteLine(ue.GetString(b2));
b3 = rsa.Decrypt(b2, true);//解密
Console.WriteLine(ue.GetString(b3));
Console.ReadLine();
}
}
}