Migrate encryption consumers to AES-GCM
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
|
||||
namespace Sarand.BusinessMgr.Net.Standard.Base.Data
|
||||
{
|
||||
public static class SbmEncryptionPurpose
|
||||
{
|
||||
// --- Definitions ---
|
||||
|
||||
public const String WindowsServiceRequest = "BusinessMgr:WindowsService:Request";
|
||||
public const String WindowsServiceResponse = "BusinessMgr:WindowsService:Response";
|
||||
public const String ControlKeepLoggedIn = "BusinessMgr:Control:KeepLoggedIn";
|
||||
public const String PortalKeepLoggedIn = "BusinessMgr:Portal:KeepLoggedIn";
|
||||
public const String ControlPasswordReset = "BusinessMgr:Control:PasswordReset";
|
||||
public const String PortalPasswordReset = "BusinessMgr:Portal:PasswordReset";
|
||||
public const String PortalDemoRegistration = "BusinessMgr:Portal:DemoRegistration";
|
||||
public const String ControlSessionParameters = "BusinessMgr:Control:SessionParameters";
|
||||
public const String PortalSessionParameters = "BusinessMgr:Portal:SessionParameters";
|
||||
|
||||
// --- The End ---
|
||||
}
|
||||
}
|
||||
@@ -1,70 +1,47 @@
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.Data;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using System;
|
||||
|
||||
namespace Sarand.BusinessMgr.Net.Standard.Base.Data
|
||||
{
|
||||
//=======================================================================
|
||||
public static class SbmWindowsServiceCrypter
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
// --- Data Members ---
|
||||
|
||||
/// <summary>
|
||||
/// Encryption is shared between Windows Service app and mobile
|
||||
/// </summary>
|
||||
private static readonly String requestDataKey = "<Sarand>~{BusinessMgr}#[WindowsService]&/DataCryption/*|RequestData|";
|
||||
private static readonly String responseDataKey = "{Sarand}+(BusinessMgr)%\\WindowsService/=<DataCryption>@:Response:";
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// R e q u e s t D a t a
|
||||
//-------------------------------------------------------------------
|
||||
// --- Request Data ---
|
||||
|
||||
/// <summary>Encrypt request data</summary>
|
||||
public static String EncryptRequestData(String value)
|
||||
{
|
||||
try
|
||||
{
|
||||
return SacsAesIvCrypter.Encrypt(value, requestDataKey);
|
||||
}
|
||||
catch (Exception exc) { SaLogger.Debug($"EncryptRequestData {ExceptionUtil.GetErrorStateMessage(exc)}"); }
|
||||
return value;
|
||||
return SacsAesGcmCrypter.Encrypt(value, requestDataKey, SbmEncryptionPurpose.WindowsServiceRequest);
|
||||
}
|
||||
|
||||
/// <summary>Decrypt request data</summary>
|
||||
public static String DecryptRequestData(String value)
|
||||
{
|
||||
try
|
||||
{
|
||||
return SacsAesIvCrypter.Decrypt(value, requestDataKey);
|
||||
}
|
||||
catch (Exception exc) { SaLogger.Debug($"DecryptRequestData {ExceptionUtil.GetErrorStateMessage(exc)}"); }
|
||||
return value;
|
||||
return SacsAesGcmCrypter.Decrypt(value, requestDataKey, SbmEncryptionPurpose.WindowsServiceRequest);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// R e s p o n s e D a t a
|
||||
//-------------------------------------------------------------------
|
||||
// --- Response Data ---
|
||||
|
||||
/// <summary>Encrypt response data</summary>
|
||||
public static String EncryptResponseData(String value)
|
||||
{
|
||||
try
|
||||
{
|
||||
return SacsAesIvCrypter.Encrypt(value, responseDataKey);
|
||||
}
|
||||
catch (Exception exc) { SaLogger.Debug($"EncryptRequestData {ExceptionUtil.GetErrorStateMessage(exc)}"); }
|
||||
return value;
|
||||
return SacsAesGcmCrypter.Encrypt(value, responseDataKey, SbmEncryptionPurpose.WindowsServiceResponse);
|
||||
}
|
||||
|
||||
/// <summary>Decrypt response data</summary>
|
||||
public static String DecryptResponseData(String value)
|
||||
{
|
||||
try
|
||||
{
|
||||
return SacsAesIvCrypter.Decrypt(value, responseDataKey);
|
||||
}
|
||||
catch (Exception exc) { SaLogger.Debug($"EncryptRequestData {ExceptionUtil.GetErrorStateMessage(exc)}"); }
|
||||
return value;
|
||||
return SacsAesGcmCrypter.Decrypt(value, responseDataKey, SbmEncryptionPurpose.WindowsServiceResponse);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// --- The End ---
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user