Sage.Encryption 1.0.0

dotnet add package Sage.Encryption --version 1.0.0
                    
NuGet\Install-Package Sage.Encryption -Version 1.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="Sage.Encryption" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Sage.Encryption" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Sage.Encryption" />
                    
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 Sage.Encryption --version 1.0.0
                    
#r "nuget: Sage.Encryption, 1.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 Sage.Encryption@1.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=Sage.Encryption&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Sage.Encryption&version=1.0.0
                    
Install as a Cake Tool

Sage.Encryption

简介

Sage.Encryption 提供了加密和解密功能,支持多种加密算法。如果需要DI,请添加扩展Sage.Encryption.ServiceExtensions

主要特性

  • AES 加密/解密
  • AES-GCM 加密/解密
  • Windows 安全数据存储
  • 同步和异步 API
  • 完全兼容 AOT 编译

使用示例

using Sage.Encryption;

// 创建加密服务
var encryptionOptions = new EncryptionOptions
{
    Password = "your-secure-password",
    Salt = "your-salt-value",
    Iterations = 10000
};


IEncryptionService encryptionService = new 
AesEncryptionService(
    encryptionOptions.Password,
    encryptionOptions.Salt,
    encryptionOptions.Iterations);

// 加密字符串
string plainText = "Hello, World!";
byte[] encrypted = encryptionService.Encrypt
(plainText);

// 解密
string decrypted = encryptionService.DecryptToString
(encrypted);
// decrypted 应该等于 "Hello, World!"


// 如果需要DI,请添加 Sage.Encryption.ServiceExtensions
// 注册数据安全存储功能
services.AddSingleton<IWindowsSecureDataStorage, WindowsSecureDataStorage>(sp =>
    new WindowsSecureDataStorage("DomainMaster", "WinServiceLiveIdea"));

// 更新系统配置
_windowsSecureDataStorage?.UpdateData(
    "SystemSettings",//Key
    old => //更新逻辑
    {
        old ??= new SystemSettings();//如果Key的配置不存在则创建一个新的
        old.ServiceSetting ??= new WebServiceSetting();//如果ServiceSetting为null则新建,也可以直接等于有数据的WebServiceSetting,如果不是更新全部字段,则使用当前方法。
        old.ServiceSetting.Address = newSetting.Address;// 要更新的字段
        old.ServiceSetting.ServiceMode = newSetting.ServiceMode;
        return old;
     },
        new SystemSettings { ServiceSetting = newSetting },//如果配置不存在默认创建的新对象,这里直接使用了上面创建的
        AppJsonSerializerContext.Default.SystemSettings
     );

// 获取系统配置
if (_windowsSecureDataStorage.TryGetData(
    key: "SystemSettings",
    jsonTypeInfo: AppJsonSerializerContext.Default.SystemSettings,
    out SystemSettings? setting))

许可证

版权所有 © 2025 甲壳虫科技 团队。

贡献

欢迎提交问题和功能请求。 QQ Group: 1054304346

作者

甲壳虫科技

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Sage.Encryption:

Package Downloads
Sage.Encryption.ServiceExtensions

Sage.Encryption的服务扩展提供了将加密服务集成到依赖注入容器的扩展方法。

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 115 7/16/2025