Skip to content

Commit

Permalink
Fix null or empty string encryption
Browse files Browse the repository at this point in the history
  • Loading branch information
Eastrall committed May 12, 2023
1 parent 6dc25da commit ebbaf6e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<AssemblyName>EntityFrameworkCore.DataEncryption</AssemblyName>
<RootNamespace>Microsoft.EntityFrameworkCore.DataEncryption</RootNamespace>
<IsPackable>true</IsPackable>
<Version>4.0.0</Version>
<Version>4.0.1</Version>
<Authors>Filipe GOMES PEIXOTO</Authors>
<PackageId>EntityFrameworkCore.DataEncryption</PackageId>
<PackageProjectUrl>https://github.com/Eastrall/EntityFrameworkCore.DataEncryption</PackageProjectUrl>
Expand All @@ -20,7 +20,7 @@
<Copyright>Filipe GOMES PEIXOTO © 2019 - 2023</Copyright>
<Description>A plugin for Microsoft.EntityFrameworkCore to add support of encrypted fields using built-in or custom encryption providers.</Description>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageReleaseNotes>https://github.com/Eastrall/EntityFrameworkCore.DataEncryption/releases/tag/v4.0.0</PackageReleaseNotes>
<PackageReleaseNotes>https://github.com/Eastrall/EntityFrameworkCore.DataEncryption/releases/tag/v4.0.1</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@ private static TOutput Encrypt<TInput, TOutput>(TInput input, IEncryptionProvide
{
byte[] inputData = input switch
{
string => Encoding.UTF8.GetBytes(input.ToString()),
string => !string.IsNullOrEmpty(input.ToString()) ? Encoding.UTF8.GetBytes(input.ToString()) : null,
byte[] => input as byte[],
_ => null,
};

byte[] encryptedRawBytes = encryptionProvider.Encrypt(inputData);

if (encryptedRawBytes is null)
{
return default;
}

object encryptedData = storageFormat switch
{
StorageFormat.Default or StorageFormat.Base64 => Convert.ToBase64String(encryptedRawBytes),
Expand Down

0 comments on commit ebbaf6e

Please sign in to comment.