Skip to content

Commit

Permalink
refactor: move deserializedSecret to correct location
Browse files Browse the repository at this point in the history
  • Loading branch information
HunorTotBagi committed Feb 9, 2024
1 parent 90d0fef commit 7692ff9
Showing 1 changed file with 2 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace Backbone.Crypto.Implementations;
public class LibsodiumSymmetricEncrypter : ISymmetricEncrypter
{
public static byte[] DecryptXChaCha20Poly1305(byte[] body, string serializedSecret)
public static byte[] DecryptXChaCha20Poly1305(byte[] body, byte[] key)
{
var bodyString = Encoding.UTF8.GetString(body);
var deserializedBody = JsonSerializer.Deserialize<CryptoCipher>(bodyString,
Expand All @@ -22,11 +22,6 @@ public static byte[] DecryptXChaCha20Poly1305(byte[] body, string serializedSecr
var payload = Convert.FromBase64String(cipherText);
var nonce = Convert.FromBase64String(deserializedBody.nnc);

var deserializedSecret = JsonSerializer.Deserialize<Secret>(serializedSecret,
new JsonSerializerOptions { Converters = { new UrlSafeBase64ToByteArrayJsonConverter() } });

var key = Convert.FromBase64String(deserializedSecret!.key + "=");

return DecryptXChaCha20Poly1305(payload, nonce, key);
}

Expand Down Expand Up @@ -71,7 +66,7 @@ public ConvertibleString Decrypt(ConvertibleString encryptedMessage, Convertible
ArgumentNullException.ThrowIfNull(key);

var body = encryptedMessage.BytesRepresentation;
var serializedSecret = key.Utf8Representation;
var serializedSecret = key.BytesRepresentation;

try
{
Expand Down

0 comments on commit 7692ff9

Please sign in to comment.