資源簡介
親測可用,可參考:https://blog.csdn.net/qq_37835111/article/details/87358779

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.IO;
using?System.Security.Cryptography;
using?System.Text;
///?
///?描述:RSA公鑰加密私鑰解密工具類
///?功能:RSA公鑰加密、私鑰解密、私鑰簽名、公鑰驗簽??
///?作者:yoyohan
///?創建時間:2019-02-12?09:49:41
///?
public?sealed?class?RSACrypt1
{
????///???
????///?私鑰簽名??
????///? ??
????///?待簽名字符串??
????///?私鑰??
????///?編碼格式??
????///?簽名后字符串 ??
????public?static?string?sign(string?content?string?privateKey?string?input_charset)
????{
????????byte[]?Data?=?Encoding.GetEncoding(input_charset).GetBytes(content);
????????RSACryptoServiceProvider?rsa?=?DecodePemPrivateKey(privateKey);
????????SHA1?sh?=?new?SHA1CryptoServiceProvider();
????????byte[]?signData?=?rsa.SignData(Data?sh);
????????return?Convert.Tobase64String(signData);
????}
????///???
????///?公鑰驗簽??
????///? ??
????///?待驗簽字符串??
????///?簽名??
????///?公鑰??
????///?編碼格式??
????///?true(通過),false(不通過) ??
????public?static?bool?verify(string?content?string?signedString?string?publicKey?string?input_charset)
????{
????????bool?result?=?false;
????????byte[]?Data?=?Encoding.GetEncoding(input_charset).GetBytes(content);
????????byte[]?data?=?Convert.Frombase64String(signedString);
????????RSAParameters?paraPub?=?ConvertFromPublicKey(publicKey);
????????RSACryptoServiceProvider?rsaPub?=?new?RSACryptoServiceProvider();
????????rsaPub.ImportParameters(paraPub);
????????SHA1?sh?=?new?SHA1CryptoServiceProvider();
????????result?=?rsaPub.VerifyData(Data?sh?data);
????????return?result;
????}
????///???
????///?公鑰加密??
????///? ??
????///?需要加密的字符串??
????///?公鑰??
????///?編碼格式??
????///?明文 ??
????public?static?string?encryptData(string?resData?string?publicKey?string?input_charset)
????{
????????byte[]?DataToEncrypt?=?Encoding.ASCII.GetBytes(resData);
????????string?result?=?encrypt(DataToEncrypt?publicKey?input_charset);
????????return?result;
????}
????///???
????///?私鑰解密??
????///? ??
????///?加密字符串??
????///?私鑰??
????///?編碼格式??
????///?明文 ??
????public?static?string?decryptData(string?resData?string?privateKey?string?input_charset)
????{
????????byte[]?DataToDecrypt?=?Convert.Frombase64String(resData);
????????string?result?=?““;
????????for?(int?j?=?0;?j?????????{
????????????byte[]?buf?=?new?byte[128];
????????????for?(int?i?=?0;?i?128;?i++)
????????????{
????????????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????2371584??2018-04-08?23:30??RSATool\BouncyCastle.Crypto.dll
?????文件???????15569??2019-02-15?11:50??RSATool\RSACrypt1.cs
?????文件????????5394??2019-02-15?13:29??RSATool\RSACrypt2.cs
?????文件???????15628??2019-02-15?14:03??RSATool\微信截圖_20190215140253.png
?????目錄???????????0??2019-02-15?14:03??RSATool\
- 上一篇:c#窗體應用程序實現對數據庫的增刪查改
- 下一篇:大富翁簡版小游戲
評論
共有 條評論