EasyCryptoSalt 1.0.3

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

Read this page in English

EasyCryptoSalt

O EasyCryptoSalt é uma biblioteca simples e eficiente para operações criptográficas em .NET. Ele oferece funcionalidades para hashing seguro usando o algoritmo SHA-256, juntamente com a capacidade de comparar hashes utilizando uma chave e um salt.

Principais Recursos

  • Esta versão utiliza .NET Standard 2.0, tornando-o reutilizável em várias plataformas .NET.
  • Hashing Seguro: Gere hashes seguros usando o algoritmo de hash SHA-256.
  • Comparação de Hashes: Verifique se o texto simples corresponde ao hash fornecido com facilidade.
  • Segurança Adicional com Salt: Utilize um salt adicional para aumentar a segurança dos hashes gerados.

Instalação

Para instalar o pacote NuGet EasyCryptoSalt, execute o seguinte comando no console do Gerenciador de Pacotes NuGet:

    dotnet add package EasyCryptoSalt --version 1.0.3

Configuração

Certifique-se de que o arquivo appsettings.json contém a seção CryptoConfigurations com as chaves necessárias:

{
   "CryptoConfigurations": {
        "Key": "Exemplo de Chave `^AOUWNW16h*634+=tq51#2fa8091$2jnsais71298>shsady|==",
        "AuthSalt": "Exemplo de Auth salt ``àadskldjlskjdlk\gwt257__1816!?}[oap725-1%"
   }
}

Exemplo de Uso Modo 1

using EasyCryptoSalt;

// Criar uma instância de Crypto
var crypto = Crypto.Instance;

// Gerar um hash seguro
string hashedText = crypto.Encrypt("Texto a ser hashado");

// Verificar se um texto simples corresponde a um hash
bool isMatch = crypto.Verify("Texto a ser verificado", hashedText);

Exemplo de Uso Modo 2

#program.cs
using EasyCryptoSalt;

var builder = WebApplication.CreateBuilder(args);
builder.Services.Configure<CryptoOptions>(configuration.GetSection("CryptoConfigurations"));
builder.Services.AddSingleton<ICrypto, Crypto>();

var app = builder.Build();      
app.Run();

#ExampleClass.cs 
using EasyCryptoSalt;

public class ExampleClass
{
  private readonly ICrypto _crypto;
  public ExampleClass(ICrypto crypto)
  {
    _crypto = crypto;
  }

  public void UseCrypto()
  {
    // Gerar um hash seguro
    string hashedText = crypto.Encrypt("Texto a ser hashado");

    // Verificar se um texto simples corresponde a um hash
    bool isMatch = crypto.Verify("Texto a ser verificado", hashedText);
  }
}        

Classe CryptoOptions

public class CryptoOptions
{
    public string Key { get; set; }
    public string AuthSalt { get; set; }
}

Classe Crypto

Descrição

A classe Crypto é responsável por realizar operações criptográficas, incluindo a geração de hashes com SHA-256 e a comparação de hashes utilizando uma chave e um salt.

Propriedades

  • Instance: Propriedade estática que retorna uma instância singleton da classe Crypto.

Construtores

  • Crypto(): Construtor privado que inicializa a chave e o salt a partir do arquivo de configuração appsettings.json.
  • Crypto(IOptions<CryptoOptions> options): Construtor público que inicializa a chave e o salt a partir das opções fornecidas no arquivo de configuração appsettings.json.

Métodos

public async Task<string> Encrypt(string input)
  • Descrição: Gera um hash com salt para o input fornecido.
  • Parâmetros: input (string): Texto a ser hashado.
  • Retorno: string: Hash com salt em formato Base64.
public async Task<bool> Verify(string plainText, string hash)
  • Descrição: Verifica se o texto simples fornecido corresponde ao hash fornecido.
  • Parâmetros: plainText (string): Texto simples a ser verificado. hash (string): Hash para comparação.
  • Retorno: bool: Retorna true se o texto simples gerar o mesmo hash; caso contrário, false.
private byte[] GenerateSalt()
  • Descrição: Gera um salt aleatório baseado na chave Auth Salt definida em appsettings.json.
  • Retorno: byte[]: Salt aleatório.

Observações:

  • Certifique-se de configurar corretamente a chave e o salt no arquivo de configuração appsettings.json para garantir a segurança adequada dos hashes gerados.

    {
      "CryptoConfigurations": {
        "Key": "exemplo de Chave ",
        "AuthSalt": "exemplo de Auth salt"
      }
    }
    
  • Esta biblioteca é projetada para ser fácil de usar e oferecer segurança robusta para suas necessidades criptográficas em .NET.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.0.3 567 6/18/2024
1.0.1 603 6/3/2024
1.0.0 455 6/3/2024