Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed encrypted bytes to put tag last which matches the Java Sample #87

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Encryption/Codec/EncryptionCodec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public Task<IReadOnlyCollection<Payload>> DecodeAsync(IReadOnlyCollection<Payloa

private byte[] Encrypt(byte[] data)
{
// Our byte array will have a const-length nonce, const-length tag, and
// then the encrypted data. In real-world use, one may want to put nonce
// Our byte array will have a const-length nonce, the encrypted data, and
// then a const-length tag. In real-world use, one may want to put nonce
// and/or tag lengths in here.
var bytes = new byte[NonceSize + TagSize + data.Length];

Expand All @@ -73,7 +73,7 @@ private byte[] Encrypt(byte[] data)
// Perform encryption
using (var aes = new AesGcm(key, TagSize))
{
aes.Encrypt(nonceSpan, data, bytes.AsSpan(NonceSize + TagSize), bytes.AsSpan(NonceSize, TagSize));
aes.Encrypt(nonceSpan, data, bytes.AsSpan(NonceSize, data.Length), bytes.AsSpan(NonceSize + data.Length, TagSize));
return bytes;
}
}
Expand All @@ -85,7 +85,7 @@ private byte[] Decrypt(byte[] data)
using (var aes = new AesGcm(key, TagSize))
{
aes.Decrypt(
data.AsSpan(0, NonceSize), data.AsSpan(NonceSize + TagSize), data.AsSpan(NonceSize, TagSize), bytes.AsSpan());
data.AsSpan(0, NonceSize), data.AsSpan(NonceSize, bytes.Length), data.AsSpan(NonceSize + bytes.Length, TagSize), bytes.AsSpan());
return bytes;
}
}
Expand Down