c# sha1签名 微信_C# SHA1withRsa签名函数,加解密 封装类

【实例简介】

支付宝验名验证函数可参考此代码。 SHA1withRsa的各种操作:加密解密,加签验签。 C#源码可编译。签名调用方法:SHA1WithRSA.sign(str, key, "UTF-8");

【实例截图】

【核心代码】

SHA1withRsa

└── SHA1withRsa

├── RSA

│   ├── bin

│   │   └── Debug

│   │   ├── RSA.exe

│   │   ├── RSA.pdb

│   │   ├── RSA.vshost.exe

│   │   └── RSA.vshost.exe.manifest

│   ├── obj

│   │   └── x86

│   │   └── Debug

│   │   ├── CoreCompileInputs.cache

│   │   ├── DesignTimeResolveAssemblyReferencesInput.cache

│   │   ├── RSA.csproj.FileListAbsolute.txt

│   │   ├── RSA.csprojResolveAssemblyReference.cache

│   │   ├── RSA.exe

│   │   └── RSA.pdb

│   ├── Program.cs

│   ├── Properties

│   │   └── AssemblyInfo.cs

│   ├── RSA.csproj

│   └── SHA1WithRSA.cs

├── rsa.sln

└── rsa.suo

8 directories, 16 files

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在.NET/C#中可以使用`RSACryptoServiceProvider`类来实现SHA1WithRSA数字签名和验证。 以下是一个示例代码,展示如何使用`RSACryptoServiceProvider`类在.NET/C#中实现SHA1WithRSA数字签名和验证: ```csharp using System; using System.Security.Cryptography; using System.Text; class Program { static void Main(string[] args) { // 载私钥 string privateKey = "<RSAKeyValue><Modulus>...</Modulus><Exponent>...</Exponent><P>...</P><Q>...</Q><DP>...</DP><DQ>...</DQ><InverseQ>...</InverseQ><D>...</D></RSAKeyValue>"; RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); rsa.FromXmlString(privateKey); // 载消息 string message = "This is a test message."; // 计算SHA1哈希值 SHA1 sha1 = SHA1.Create(); byte[] hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(message)); // 使用RSA私钥对SHA1哈希值进行签名 byte[] signature = rsa.SignHash(hash, CryptoConfig.MapNameToOID("SHA1")); // 打印签名结果 Console.WriteLine("Signature: {0}", BitConverter.ToString(signature)); // 验证签名 bool result = rsa.VerifyHash(hash, CryptoConfig.MapNameToOID("SHA1"), signature); Console.WriteLine("Verification result: {0}", result); } } ``` 在上面的代码中,我们首先载了RSA私钥,然后计算了消息的SHA1哈希值,最后使用RSA私钥对SHA1哈希值进行签名,并且通过`VerifyHash`方法验证签名是否有效。签名结果可以通过打印`signature`数组来查看。请注意,此示例代码仅用于演示目的,实际使用时需要注意安全性问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值