33 lines
865 B
C#
33 lines
865 B
C#
using Sarand.Net.Standard.Base.Helpers;
|
|
using System;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
|
|
namespace Sarand.Net.Standard.Base.Data
|
|
{
|
|
public static class SacsAesGcmCrypter
|
|
{
|
|
// --- Key Derivation ---
|
|
|
|
private static Byte[] CreateKey(String keyValue)
|
|
{
|
|
ArgumentException.ThrowIfNullOrWhiteSpace(keyValue);
|
|
return SHA256.HashData(Encoding.UTF8.GetBytes(keyValue));
|
|
}
|
|
|
|
// --- Authenticated Encryption ---
|
|
|
|
public static String Encrypt(this String clearValue, String encryptionKey, String purpose)
|
|
{
|
|
return SacsAuthenticatedEncryption.Encrypt(clearValue, CreateKey(encryptionKey), purpose);
|
|
}
|
|
|
|
public static String Decrypt(this String encryptedValue, String encryptionKey, String purpose)
|
|
{
|
|
return SacsAuthenticatedEncryption.Decrypt(encryptedValue, CreateKey(encryptionKey), purpose);
|
|
}
|
|
|
|
// --- The End ---
|
|
}
|
|
}
|