tests/DotNetCommon.Test/Encrypt/RSAFromX509Tests.cs
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using DotNetCommon.Encrypt;
using NUnit.Framework;
using Shouldly;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace DotNetCommon.Tests.Encrypt
{
[TestFixture]
public class RSAFromX509Tests
{
string privateKey = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Encrypt/user-rsa.pfx");
string publicKey = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Encrypt/public-rsa.cer");
string pwd = "123456";
[Test]
public void EncryptTest()
{
var rsa = new RSAFromX509(publicKey, privateKey, pwd);
var encode_str = rsa.Encrypt("https://www.baidu.com");
encode_str.ShouldNotBeNullOrWhiteSpace();
var decode_str = rsa.Decrypt(encode_str);
decode_str.ShouldNotBeNullOrWhiteSpace();
Assert.IsTrue("https://www.baidu.com" == decode_str);
encode_str = rsa.Encrypt(null);
encode_str.ShouldBeNull();
encode_str = rsa.Encrypt("");
encode_str.ShouldBeEmpty();
encode_str = rsa.Encrypt(" ");
encode_str.ShouldNotBeNullOrWhiteSpace();
}
[Test]
public void SignTest()
{
var rsa = new RSAFromX509(publicKey, privateKey, pwd);
var encode_str = rsa.Sign("https://www.baidu.com");
encode_str.ShouldNotBeNullOrWhiteSpace();
var res = rsa.Verify("https://www.baidu.com", encode_str);
Assert.IsTrue(res);
encode_str = rsa.Sign(null);
encode_str.ShouldBeNull();
encode_str = rsa.Sign("");
encode_str.ShouldBeEmpty();
encode_str = rsa.Sign(" ");
encode_str.ShouldNotBeNullOrWhiteSpace();
}
/// <summary>
/// 使用公钥加密,使用私钥解密
/// </summary>
后面还有 45 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
