WALTER | Workable Algorithms for Location-aware Transmission, Encryption Response

WalterDependencyInjectionHelper..::..UseSymmetricEncryption<(Of <(<'T>)>)> Method

Configures the use of SymmetricEncryption with a given password for classes that require it. This method extends IServiceCollection, enabling the integration of symmetric encryption into the .NET dependency injection framework.

Namespace:  Microsoft.Extensions.DependencyInjection
Assembly:  Walter (in Walter.dll)

Syntax


public static T UseSymmetricEncryption<T>(
	this T service,
	string password
)
where T : IServiceCollection

Type Parameters

T
The type of the service collection, constrained to IServiceCollection.

Parameters

service
Type: T
The instance of IServiceCollection to which the symmetric encryption configuration is added.
password
Type: String
The password used for symmetric encryption. This password is set as the default for all encryption operations.

Return Value

The service collection instance (T), allowing for method chaining in the configuration setup.

Exceptions


ExceptionCondition
[ArgumentNullException]Thrown if the provided password is null or empty.

Remarks


This method should be used during the configuration phase of the application, typically in the Startup.cs or equivalent initialization file. Ensure that the password provided meets security requirements (length, complexity, etc.). The password used in symmetric encryption is a sensitive piece of information and should be stored and handled securely. Consider providing the password through a secure mechanism, like environment variables or a secure secrets store, especially in production environments.

Examples


This sample shows how to register SymmetricEncryption with a application password to securely and efficiently use it in your application.
C#
public class Startup
   {
       public void ConfigureServices(IServiceCollection services)
       {
           // Other service configurations...

           // Configure SymmetricEncryption with a default password
           services.UseSymmetricEncryption("your-secure-password");

           // Continue with service configuration...
       }
   }
Use DI to get the SymmetricEncryption instance injected in your class
class MySecureStorage
{
    private readonly SymmetricEncryption _cypher;
    public MySecureStorage(SymmetricEncryption cypher)
    {
        _cypher= cypher;

    }
    ... rest of your code
}