标签:style blog http color os io for art
关于RSACryption帮助类定义见RSACryption
一、加密与解密
//定义明文和密文变量 string plaintext = "天道酬勤,厚德载物!"; string ciphertext = ""; //产生密钥 string prikey = "", pubkey = ""; rsa.RSAKey(out prikey, out pubkey); //加密解密过程 ciphertext = rsa.RSAEncrypt(pubkey, plaintext); plaintext = rsa.RSADecrypt(prikey, ciphertext);
二、签名与验证
//获取明文Hash值 byte[] plaintextHash = null; rsa.GetHash(plaintext, ref plaintextHash); //获取签名密文 string SignatureCiphertext = null; rsa.SignatureFormatter(prikey, plaintextHash, ref SignatureCiphertext); //验证 string verify = rsa.SignatureDeformatter(pubkey, plaintextHash, SignatureCiphertext) ? "OK!没问题" : "NO!内容被篡改了";
Tips:利用RSA的签名和验证功能还可简单实现软件注册码功能,签名即注册码,验证即验证。
相关链接
标签:style blog http color os io for art
原文地址:http://www.cnblogs.com/njl041x/p/3872916.html