/// <summary> /// /// </summary> /// <param name="rsaKey"></param> /// <param name="path"></param> /// <returns></returns> public static bool SaveRSAPubliceKey(RSAKey rsaKey, string path) { //加密解密用到的公钥与私钥 using (StreamWriter streamWriter = new StreamWriter(path, false)) { streamWriter.Write(rsaKey.PublicKey); return(true); } }
public static RSAKey GenerateRSAKey(int keyLenght) { //加密解密用到的公钥与私钥 RSACryptoServiceProvider oRSA = new RSACryptoServiceProvider(keyLenght); string privatekey = oRSA.ToXmlString(true); //私钥 string publickey = oRSA.ToXmlString(false); //公钥 RSAKey rsaKey = new RSAKey(); rsaKey.PrivateKey = privatekey; rsaKey.PublicKey = publickey; return(rsaKey); }