string outPutString = null; string prikey; string pubkey; bool isSeccess = false; using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider()) { // 公钥 pubkey = rsa.ToXmlString(false); // 私钥 prikey = rsa.ToXmlString(true); } //私钥串+特征码生成 鬼画符 using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider()) { rsa.FromXmlString(prikey); // 加密对象 RSAPKCS1SignatureFormatter f = new RSAPKCS1SignatureFormatter(rsa); f.SetHashAlgorithm("SHA1"); byte[] source = System.Text.ASCIIEncoding.ASCII.GetBytes("878"); SHA1Managed sha = new SHA1Managed(); byte[] result = sha.ComputeHash(source); byte[] b = f.CreateSignature(result); outPutString = Convert.ToBase64String(b); } //公钥串+特征码+鬼画符 解码. using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider()) { rsa.FromXmlString(pubkey); RSAPKCS1SignatureDeformatter f = new RSAPKCS1SignatureDeformatter(rsa); f.SetHashAlgorithm("SHA1"); byte[] key = Convert.FromBase64String(outPutString); SHA1Managed sha = new SHA1Managed(); byte[] name = sha.ComputeHash(ASCIIEncoding.ASCII.GetBytes("878")); if (f.VerifySignature(name, key)) isSeccess = true; else isSeccess = false; }