Skip to content

Commit ebbaf6e

Browse files
committed
Fix null or empty string encryption
1 parent 6dc25da commit ebbaf6e

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/EntityFrameworkCore.DataEncryption/EntityFrameworkCore.DataEncryption.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<AssemblyName>EntityFrameworkCore.DataEncryption</AssemblyName>
88
<RootNamespace>Microsoft.EntityFrameworkCore.DataEncryption</RootNamespace>
99
<IsPackable>true</IsPackable>
10-
<Version>4.0.0</Version>
10+
<Version>4.0.1</Version>
1111
<Authors>Filipe GOMES PEIXOTO</Authors>
1212
<PackageId>EntityFrameworkCore.DataEncryption</PackageId>
1313
<PackageProjectUrl>https://github.com/Eastrall/EntityFrameworkCore.DataEncryption</PackageProjectUrl>
@@ -20,7 +20,7 @@
2020
<Copyright>Filipe GOMES PEIXOTO © 2019 - 2023</Copyright>
2121
<Description>A plugin for Microsoft.EntityFrameworkCore to add support of encrypted fields using built-in or custom encryption providers.</Description>
2222
<PackageLicenseFile>LICENSE</PackageLicenseFile>
23-
<PackageReleaseNotes>https://github.com/Eastrall/EntityFrameworkCore.DataEncryption/releases/tag/v4.0.0</PackageReleaseNotes>
23+
<PackageReleaseNotes>https://github.com/Eastrall/EntityFrameworkCore.DataEncryption/releases/tag/v4.0.1</PackageReleaseNotes>
2424
<PackageReadmeFile>README.md</PackageReadmeFile>
2525
</PropertyGroup>
2626

src/EntityFrameworkCore.DataEncryption/Internal/EncryptionConverter.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,18 @@ private static TOutput Encrypt<TInput, TOutput>(TInput input, IEncryptionProvide
3030
{
3131
byte[] inputData = input switch
3232
{
33-
string => Encoding.UTF8.GetBytes(input.ToString()),
33+
string => !string.IsNullOrEmpty(input.ToString()) ? Encoding.UTF8.GetBytes(input.ToString()) : null,
3434
byte[] => input as byte[],
3535
_ => null,
3636
};
3737

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

40+
if (encryptedRawBytes is null)
41+
{
42+
return default;
43+
}
44+
4045
object encryptedData = storageFormat switch
4146
{
4247
StorageFormat.Default or StorageFormat.Base64 => Convert.ToBase64String(encryptedRawBytes),

0 commit comments

Comments
 (0)