加密解密测试代码完成
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-09-19 11:45:23 +08:00
parent de274e00d6
commit fb067534e7
7 changed files with 178 additions and 53 deletions
+53 -10
View File
@@ -126,7 +126,7 @@ namespace IRaCIS.Application.Services
var model4= _mapper.Map(model1, model2);
var model4 = _mapper.Map(model1, model2);
await _trialBodyPartRepository.FirstOrDefaultAsync();
@@ -245,9 +245,37 @@ namespace IRaCIS.Application.Services
return ResponseOutput.Ok();
}
[UnitOfWork]
public async Task<string> Get()
public class TestEncrept
{
public string Name { get; set; }
public string Code { get; set; }
}
public IResponseOutput TestEncreptTest(TestEncrept testModel)
{
return ResponseOutput.Ok(testModel);
}
//etx5EzcF9XWA6ICzQB5ywEEextuhmUwaHM2TmyyCC8Q=
[HttpPut("{name}/{code}")]
public IResponseOutput TestEncreptTest2(string name, string code)
{
return ResponseOutput.Ok($"name:{name} Code: {code}");
}
public IResponseOutput TestEncreptTest3(string name, string Code)
{
return ResponseOutput.Ok($"name:{name} Code: {Code}");
}
[UnitOfWork]
public async Task<string> Get([FromServices] IOptionsMonitor<IRCEncreptOption> _encreptResponseMonitor)
{
var _IRCEncreptOption = _encreptResponseMonitor.CurrentValue;
string plainText = "Hello, BouncyCastle!";
string key = "12345678901234567890123456789012"; // AES 密钥长度应为 16 字节(128 位)
string iv = "your-iv-12345678"; // IV 长度为 16 字节
@@ -276,17 +304,32 @@ namespace IRaCIS.Application.Services
Console.WriteLine($"解密后的数据: {decrypte}");
// Generate RSA keys
var keyPair = RSAEncryption.GenerateRSAKeyPair(2048);
//// Generate RSA keys
//var keyPair = RSAEncryption.GenerateRSAKeyPair(2048);
// Export the public and private keys to PEM format
string publicKey = RSAEncryption.ExportPublicKey(keyPair.Public);
string privateKey = RSAEncryption.ExportPrivateKey(keyPair.Private);
//// Export the public and private keys to PEM format
//string publicKey = RSAEncryption.ExportPublicKey(keyPair.Public);
//string privateKey = RSAEncryption.ExportPrivateKey(keyPair.Private);
//Console.WriteLine("Public Key:");
//Console.WriteLine(publicKey);
//Console.WriteLine($"{Convert.ToBase64String(Encoding.UTF8.GetBytes(publicKey))}");
//Console.WriteLine("\nPrivate Key:");
//Console.WriteLine(privateKey);
//Console.WriteLine($"{Convert.ToBase64String(Encoding.UTF8.GetBytes(privateKey))}");
var publicKey = Encoding.UTF8.GetString(Convert.FromBase64String(_IRCEncreptOption.Base64RSAPublicKey));
var privateKey = Encoding.UTF8.GetString(Convert.FromBase64String(_IRCEncreptOption.Base64RSAPrivateKey));
Console.WriteLine("Public Key:");
Console.WriteLine(publicKey);
Console.WriteLine("\nPrivate Key:");
Console.WriteLine(privateKey);
Console.WriteLine("\nPrivate Key:");
Console.WriteLine(publicKey);
Console.WriteLine("encrept sys Key:");
Console.WriteLine($"\n{RSAEncryption.Encrypt(publicKey, key)}");
// Data to encrypt
string dataToEncrypt = "Hello, RSA!";