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.
<PackageVersion Include="WYJ.Security" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="WYJ.Security" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version 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.
#:package WYJ.Security@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=WYJ.Security&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=WYJ.Security&version=2.0.0
                    
Install as a Cake Tool

使用示例

简单示例

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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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 326 9/9/2023
1.0.0 392 7/28/2022