Pass Span instead of Memory
This commit is contained in:
parent
650fe99990
commit
ccc00d8e80
10 changed files with 45 additions and 38 deletions
|
|
@ -4,6 +4,6 @@ namespace IdentityShroud.Core.Contracts;
|
|||
|
||||
public interface IDataEncryptionService
|
||||
{
|
||||
EncryptedValue Encrypt(ReadOnlyMemory<byte> plain);
|
||||
EncryptedValue Encrypt(ReadOnlySpan<byte> plain);
|
||||
byte[] Decrypt(EncryptedValue input);
|
||||
}
|
||||
|
|
@ -6,6 +6,6 @@ namespace IdentityShroud.Core.Contracts;
|
|||
|
||||
public interface IDekEncryptionService
|
||||
{
|
||||
EncryptedDek Encrypt(ReadOnlyMemory<byte> plain);
|
||||
EncryptedDek Encrypt(ReadOnlySpan<byte> plain);
|
||||
byte[] Decrypt(EncryptedDek input);
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ public static class Encryption
|
|||
new(1, 12, 16), // version 1
|
||||
];
|
||||
|
||||
public static byte[] Encrypt(ReadOnlyMemory<byte> plaintext, ReadOnlySpan<byte> key)
|
||||
public static byte[] Encrypt(ReadOnlySpan<byte> plaintext, ReadOnlySpan<byte> key)
|
||||
{
|
||||
const int versionNumber = 1;
|
||||
AlgVersion versionParams = _versions[versionNumber];
|
||||
|
|
@ -31,7 +31,7 @@ public static class Encryption
|
|||
// use the spans to place the data directly in its place
|
||||
RandomNumberGenerator.Fill(nonce);
|
||||
using var aes = new AesGcm(key, versionParams.TagSize);
|
||||
aes.Encrypt(nonce, plaintext.Span, cipher, tag);
|
||||
aes.Encrypt(nonce, plaintext, cipher, tag);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ public class DataEncryptionService(
|
|||
return Encryption.Decrypt(input.Value, key);
|
||||
}
|
||||
|
||||
public EncryptedValue Encrypt(ReadOnlyMemory<byte> plain)
|
||||
public EncryptedValue Encrypt(ReadOnlySpan<byte> plain)
|
||||
{
|
||||
var dek = GetActiveDek();
|
||||
var key = dekCryptor.Decrypt(dek.KeyData);
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ public class DekEncryptionService : IDekEncryptionService
|
|||
// throw new Exception("Key must be 256 bits (32 bytes) for AES‑256‑GCM.");
|
||||
}
|
||||
|
||||
public EncryptedDek Encrypt(ReadOnlyMemory<byte> plaintext)
|
||||
public EncryptedDek Encrypt(ReadOnlySpan<byte> plaintext)
|
||||
{
|
||||
var encryptionKey = ActiveKey;
|
||||
byte[] cipher = Encryption.Encrypt(plaintext, encryptionKey.Key);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue