using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; namespace MeterVision.Util { //我们需要生成一对 RSA 密钥(公钥和私钥)。你可以使用以下代码生成密钥对: public class RSAKeyGenerator { public static Tuple GenerateKeys() { using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(2048)) // 2048位密钥长度 { // 生成私钥(包括公钥信息) string privateKey = rsa.ToXmlString(true); // true 表示包含私钥 // 生成公钥 string publicKey = rsa.ToXmlString(false); // false 表示只包含公钥 return Tuple.Create(publicKey, privateKey); } } } //-------------------- }