WYJ.Security 2.0.0

dotnet add package WYJ.Security --version 2.0.0                
NuGet\Install-Package WYJ.Security -Version 2.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WYJ.Security" Version="2.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add WYJ.Security --version 2.0.0                
#r "nuget: WYJ.Security, 2.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install WYJ.Security as a Cake Addin
#addin nuget:?package=WYJ.Security&version=2.0.0

// Install WYJ.Security as a Cake Tool
#tool nuget:?package=WYJ.Security&version=2.0.0                

使用示例

简单示例

using System.Security.Cryptography;

SymmetricCryptoService cryptoServiceProvider = new SymmetricCryptoService(new SymmetricCryptoServiceOption
{
    Password = "anystring",
    SymmetricAlgorithmName = SymmetricAlgorithmName.Des,
});

string file = "C:\\README.txt";
cryptoServiceProvider.EncodeFile(file);
cryptoServiceProvider.DecodeFile(file);

完整示例 Program.cs

using System.Security.Cryptography;

SymmetricCryptoService CryptoServiceProvider = new SymmetricCryptoService(new SymmetricCryptoServiceOption
{
    Password = "anystring",
    SymmetricAlgorithmName = SymmetricAlgorithmName.Des,
});

string dir = Environment.CurrentDirectory;
string[] files = Directory.GetFiles(dir).Where(x=>Path.GetExtension(x) == ".txt").ToArray();
if(files.Length == 0)
{
    Console.WriteLine("未找到密码文件。请按任意键退出。");
    Console.ReadKey();
    return;
}
string[] fileOptions = files.Select((x,i) => $"{i + 1}. {Path.GetFileNameWithoutExtension(x)}").ToArray();

string? option;
string? cmd;
while (true)
{
    Console.WriteLine("请选择:(输入数字,然后回车。数字不在范围退出。");
    foreach (var showText in fileOptions)
    {
        Console.WriteLine(showText);
    }
    option = ReadLine();
    if(!int.TryParse(option,out int i))
    {
        Console.WriteLine("输入错误。请重新输入。");
        continue;
    }
    if(i > files.Length || i<1)
    {
        Console.WriteLine("数字不在范围。");
        break ;
    }
    
    Console.WriteLine("加密请输入 encode,解密请输入 decode,其它退出");

    cmd = ReadLine();
    string file = files[i-1];
    if(cmd?.ToLower() == "encode")
    {
        CryptoServiceProvider.EncodeFile(file);
        Console.WriteLine("加密成功");
        continue;
    }
    if (cmd?.ToLower() == "decode")
    {
        CryptoServiceProvider.DecodeFile(file);
        Console.WriteLine("解密成功");
        continue;
    }
    break;
}

static string? ReadLine(string prefix = ">>>")
{
    Console.Write(prefix);
    return Console.ReadLine();
}
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 156 9/9/2023
1.0.0 192 7/28/2022