├── .github
└── ISSUE_TEMPLATE
│ ├── ---bug-report.md
│ ├── ---custom-issue-template.md
│ └── --feature-request.md
├── .gitignore
├── .idea
└── .idea.EntityFrameworkCore.DataEncryption
│ └── .idea
│ ├── .gitignore
│ ├── encodings.xml
│ ├── indexLayout.xml
│ └── vcs.xml
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── EntityFrameworkCore.DataEncryption.sln
├── LICENSE
├── PULL_REQUEST_TEMPLATE.md
├── README.md
├── common.props
├── sample
└── EntityFrameworkCore.DataEncryption.Sample
│ ├── Context
│ └── SampleDbContext.cs
│ ├── Controllers
│ └── AuthorController.cs
│ ├── Entities
│ └── Author.cs
│ ├── EntityFrameworkCore.DataEncryption.Sample.csproj
│ ├── Migrations
│ ├── 20220514214104_Initial.Designer.cs
│ ├── 20220514214104_Initial.cs
│ └── SampleDbContextModelSnapshot.cs
│ ├── Program.cs
│ ├── Properties
│ └── launchSettings.json
│ └── appsettings.json
└── src
├── EntityFrameworkCore.DataEncryption.Conversions
├── EncryptValueConverter.cs
├── EntityFrameworkCore.DataEncryption.Conversions.csproj
└── encrypt.png
└── EntityFrameworkCore.DataEncryption.Core
├── Cipher.cs
├── EntityFrameworkCore.DataEncryption.Core.csproj
└── encrypt.png
/.github/ISSUE_TEMPLATE/---bug-report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: "\U0001F41B Bug report"
3 | about: Create a report to help us improve
4 | title: "\U0001F41B [BUG]"
5 | labels: bug
6 | assignees: furkandeveloper
7 |
8 | ---
9 |
10 | **Describe the bug**
11 | A clear and concise description of what the bug is.
12 |
13 | **To Reproduce**
14 | Steps to reproduce the behavior:
15 | 1. Go to '...'
16 | 2. Click on '....'
17 | 3. Scroll down to '....'
18 | 4. See error
19 |
20 | **Expected behavior**
21 | A clear and concise description of what you expected to happen.
22 |
23 | **Screenshots**
24 | If applicable, add screenshots to help explain your problem.
25 |
26 | **Desktop (please complete the following information):**
27 | - OS: [e.g. iOS]
28 | - Browser [e.g. chrome, safari]
29 | - Version [e.g. 22]
30 |
31 | **Smartphone (please complete the following information):**
32 | - Device: [e.g. iPhone6]
33 | - OS: [e.g. iOS8.1]
34 | - Browser [e.g. stock browser, safari]
35 | - Version [e.g. 22]
36 |
37 | **Additional context**
38 | Add any other context about the problem here.
39 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/---custom-issue-template.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: "\U0001F4CC Custom issue template"
3 | about: Describe this issue template's purpose here.
4 | title: "\U0001F4CC [CUSTOM]"
5 | labels: question
6 | assignees: furkandeveloper
7 |
8 | ---
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/--feature-request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: "✨ Feature request"
3 | about: Suggest an idea for this project
4 | title: "✨ [FEATURE]"
5 | labels: enhancement
6 | assignees: furkandeveloper
7 |
8 | ---
9 |
10 | ## Summary
11 | Enter a summary of the feature you want.
12 |
13 | ## Advantage
14 | Advantages...
15 |
16 | **Additional context**
17 | Add any other context or screenshots about the feature request here.
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Build results
17 | [Dd]ebug/
18 | [Dd]ebugPublic/
19 | [Rr]elease/
20 | [Rr]eleases/
21 | x64/
22 | x86/
23 | [Aa][Rr][Mm]/
24 | [Aa][Rr][Mm]64/
25 | bld/
26 | [Bb]in/
27 | [Oo]bj/
28 | [Ll]og/
29 |
30 | # Visual Studio 2015/2017 cache/options directory
31 | .vs/
32 | # Uncomment if you have tasks that create the project's static files in wwwroot
33 | #wwwroot/
34 |
35 | # Visual Studio 2017 auto generated files
36 | Generated\ Files/
37 |
38 | # MSTest test Results
39 | [Tt]est[Rr]esult*/
40 | [Bb]uild[Ll]og.*
41 |
42 | # NUNIT
43 | *.VisualState.xml
44 | TestResult.xml
45 |
46 | # Build Results of an ATL Project
47 | [Dd]ebugPS/
48 | [Rr]eleasePS/
49 | dlldata.c
50 |
51 | # Benchmark Results
52 | BenchmarkDotNet.Artifacts/
53 |
54 | # .NET Core
55 | project.lock.json
56 | project.fragment.lock.json
57 | artifacts/
58 |
59 | # StyleCop
60 | StyleCopReport.xml
61 |
62 | # Files built by Visual Studio
63 | *_i.c
64 | *_p.c
65 | *_h.h
66 | *.ilk
67 | *.meta
68 | *.obj
69 | *.iobj
70 | *.pch
71 | *.pdb
72 | *.ipdb
73 | *.pgc
74 | *.pgd
75 | *.rsp
76 | *.sbr
77 | *.tlb
78 | *.tli
79 | *.tlh
80 | *.tmp
81 | *.tmp_proj
82 | *_wpftmp.csproj
83 | *.log
84 | *.vspscc
85 | *.vssscc
86 | .builds
87 | *.pidb
88 | *.svclog
89 | *.scc
90 |
91 | # Chutzpah Test files
92 | _Chutzpah*
93 |
94 | # Visual C++ cache files
95 | ipch/
96 | *.aps
97 | *.ncb
98 | *.opendb
99 | *.opensdf
100 | *.sdf
101 | *.cachefile
102 | *.VC.db
103 | *.VC.VC.opendb
104 |
105 | # Visual Studio profiler
106 | *.psess
107 | *.vsp
108 | *.vspx
109 | *.sap
110 |
111 | # Visual Studio Trace Files
112 | *.e2e
113 |
114 | # TFS 2012 Local Workspace
115 | $tf/
116 |
117 | # Guidance Automation Toolkit
118 | *.gpState
119 |
120 | # ReSharper is a .NET coding add-in
121 | _ReSharper*/
122 | *.[Rr]e[Ss]harper
123 | *.DotSettings.user
124 |
125 | # JustCode is a .NET coding add-in
126 | .JustCode
127 |
128 | # TeamCity is a build add-in
129 | _TeamCity*
130 |
131 | # DotCover is a Code Coverage Tool
132 | *.dotCover
133 |
134 | # AxoCover is a Code Coverage Tool
135 | .axoCover/*
136 | !.axoCover/settings.json
137 |
138 | # Visual Studio code coverage results
139 | *.coverage
140 | *.coveragexml
141 |
142 | # NCrunch
143 | _NCrunch_*
144 | .*crunch*.local.xml
145 | nCrunchTemp_*
146 |
147 | # MightyMoose
148 | *.mm.*
149 | AutoTest.Net/
150 |
151 | # Web workbench (sass)
152 | .sass-cache/
153 |
154 | # Installshield output folder
155 | [Ee]xpress/
156 |
157 | # DocProject is a documentation generator add-in
158 | DocProject/buildhelp/
159 | DocProject/Help/*.HxT
160 | DocProject/Help/*.HxC
161 | DocProject/Help/*.hhc
162 | DocProject/Help/*.hhk
163 | DocProject/Help/*.hhp
164 | DocProject/Help/Html2
165 | DocProject/Help/html
166 |
167 | # Click-Once directory
168 | publish/
169 |
170 | # Publish Web Output
171 | *.[Pp]ublish.xml
172 | *.azurePubxml
173 | # Note: Comment the next line if you want to checkin your web deploy settings,
174 | # but database connection strings (with potential passwords) will be unencrypted
175 | *.pubxml
176 | *.publishproj
177 |
178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
179 | # checkin your Azure Web App publish settings, but sensitive information contained
180 | # in these scripts will be unencrypted
181 | PublishScripts/
182 |
183 | # NuGet Packages
184 | *.nupkg
185 | # The packages folder can be ignored because of Package Restore
186 | **/[Pp]ackages/*
187 | # except build/, which is used as an MSBuild target.
188 | !**/[Pp]ackages/build/
189 | # Uncomment if necessary however generally it will be regenerated when needed
190 | #!**/[Pp]ackages/repositories.config
191 | # NuGet v3's project.json files produces more ignorable files
192 | *.nuget.props
193 | *.nuget.targets
194 |
195 | # Microsoft Azure Build Output
196 | csx/
197 | *.build.csdef
198 |
199 | # Microsoft Azure Emulator
200 | ecf/
201 | rcf/
202 |
203 | # Windows Store app package directories and files
204 | AppPackages/
205 | BundleArtifacts/
206 | Package.StoreAssociation.xml
207 | _pkginfo.txt
208 | *.appx
209 |
210 | # Visual Studio cache files
211 | # files ending in .cache can be ignored
212 | *.[Cc]ache
213 | # but keep track of directories ending in .cache
214 | !?*.[Cc]ache/
215 |
216 | # Others
217 | ClientBin/
218 | ~$*
219 | *~
220 | *.dbmdl
221 | *.dbproj.schemaview
222 | *.jfm
223 | *.pfx
224 | *.publishsettings
225 | orleans.codegen.cs
226 |
227 | # Including strong name files can present a security risk
228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
229 | #*.snk
230 |
231 | # Since there are multiple workflows, uncomment next line to ignore bower_components
232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
233 | #bower_components/
234 |
235 | # RIA/Silverlight projects
236 | Generated_Code/
237 |
238 | # Backup & report files from converting an old project file
239 | # to a newer Visual Studio version. Backup files are not needed,
240 | # because we have git ;-)
241 | _UpgradeReport_Files/
242 | Backup*/
243 | UpgradeLog*.XML
244 | UpgradeLog*.htm
245 | ServiceFabricBackup/
246 | *.rptproj.bak
247 |
248 | # SQL Server files
249 | *.mdf
250 | *.ldf
251 | *.ndf
252 |
253 | # Business Intelligence projects
254 | *.rdl.data
255 | *.bim.layout
256 | *.bim_*.settings
257 | *.rptproj.rsuser
258 | *- Backup*.rdl
259 |
260 | # Microsoft Fakes
261 | FakesAssemblies/
262 |
263 | # GhostDoc plugin setting file
264 | *.GhostDoc.xml
265 |
266 | # Node.js Tools for Visual Studio
267 | .ntvs_analysis.dat
268 | node_modules/
269 |
270 | # Visual Studio 6 build log
271 | *.plg
272 |
273 | # Visual Studio 6 workspace options file
274 | *.opt
275 |
276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
277 | *.vbw
278 |
279 | # Visual Studio LightSwitch build output
280 | **/*.HTMLClient/GeneratedArtifacts
281 | **/*.DesktopClient/GeneratedArtifacts
282 | **/*.DesktopClient/ModelManifest.xml
283 | **/*.Server/GeneratedArtifacts
284 | **/*.Server/ModelManifest.xml
285 | _Pvt_Extensions
286 |
287 | # Paket dependency manager
288 | .paket/paket.exe
289 | paket-files/
290 |
291 | # FAKE - F# Make
292 | .fake/
293 |
294 | # JetBrains Rider
295 | .idea/
296 | *.sln.iml
297 |
298 | # CodeRush personal settings
299 | .cr/personal
300 |
301 | # Python Tools for Visual Studio (PTVS)
302 | __pycache__/
303 | *.pyc
304 |
305 | # Cake - Uncomment if you are using it
306 | # tools/**
307 | # !tools/packages.config
308 |
309 | # Tabs Studio
310 | *.tss
311 |
312 | # Telerik's JustMock configuration file
313 | *.jmconfig
314 |
315 | # BizTalk build output
316 | *.btp.cs
317 | *.btm.cs
318 | *.odx.cs
319 | *.xsd.cs
320 |
321 | # OpenCover UI analysis results
322 | OpenCover/
323 |
324 | # Azure Stream Analytics local run output
325 | ASALocalRun/
326 |
327 | # MSBuild Binary and Structured Log
328 | *.binlog
329 |
330 | # NVidia Nsight GPU debugger configuration file
331 | *.nvuser
332 |
333 | # MFractors (Xamarin productivity tool) working folder
334 | .mfractor/
335 |
336 | # Local History for Visual Studio
337 | .localhistory/
338 |
339 | # BeatPulse healthcheck temp database
340 | healthchecksdb
341 |
342 | appsettings.*.json
--------------------------------------------------------------------------------
/.idea/.idea.EntityFrameworkCore.DataEncryption/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Rider ignored files
5 | /contentModel.xml
6 | /projectSettingsUpdater.xml
7 | /modules.xml
8 | /.idea.EntityFrameworkCore.DataEncryption.iml
9 | # Editor-based HTTP Client requests
10 | /httpRequests/
11 | # Datasource local storage ignored files
12 | /dataSources/
13 | /dataSources.local.xml
14 |
--------------------------------------------------------------------------------
/.idea/.idea.EntityFrameworkCore.DataEncryption/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/.idea/.idea.EntityFrameworkCore.DataEncryption/.idea/indexLayout.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/.idea.EntityFrameworkCore.DataEncryption/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Citizen Code of Conduct
2 |
3 | ## 1. Purpose
4 |
5 | A primary goal of Entity Framework Core.Data Encryption is to be inclusive to the largest number of contributors, with the most varied and diverse backgrounds possible. As such, we are committed to providing a friendly, safe and welcoming environment for all, regardless of gender, sexual orientation, ability, ethnicity, socioeconomic status, and religion (or lack thereof).
6 |
7 | This code of conduct outlines our expectations for all those who participate in our community, as well as the consequences for unacceptable behavior.
8 |
9 | We invite all those who participate in Entity Framework Core.Data Encryption to help us create safe and positive experiences for everyone.
10 |
11 | ## 2. Open [Source/Culture/Tech] Citizenship
12 |
13 | A supplemental goal of this Code of Conduct is to increase open [source/culture/tech] citizenship by encouraging participants to recognize and strengthen the relationships between our actions and their effects on our community.
14 |
15 | Communities mirror the societies in which they exist and positive action is essential to counteract the many forms of inequality and abuses of power that exist in society.
16 |
17 | If you see someone who is making an extra effort to ensure our community is welcoming, friendly, and encourages all participants to contribute to the fullest extent, we want to know.
18 |
19 | ## 3. Expected Behavior
20 |
21 | The following behaviors are expected and requested of all community members:
22 |
23 | * Participate in an authentic and active way. In doing so, you contribute to the health and longevity of this community.
24 | * Exercise consideration and respect in your speech and actions.
25 | * Attempt collaboration before conflict.
26 | * Refrain from demeaning, discriminatory, or harassing behavior and speech.
27 | * Be mindful of your surroundings and of your fellow participants. Alert community leaders if you notice a dangerous situation, someone in distress, or violations of this Code of Conduct, even if they seem inconsequential.
28 | * Remember that community event venues may be shared with members of the public; please be respectful to all patrons of these locations.
29 |
30 | ## 4. Unacceptable Behavior
31 |
32 | The following behaviors are considered harassment and are unacceptable within our community:
33 |
34 | * Violence, threats of violence or violent language directed against another person.
35 | * Sexist, racist, homophobic, transphobic, ableist or otherwise discriminatory jokes and language.
36 | * Posting or displaying sexually explicit or violent material.
37 | * Posting or threatening to post other people's personally identifying information ("doxing").
38 | * Personal insults, particularly those related to gender, sexual orientation, race, religion, or disability.
39 | * Inappropriate photography or recording.
40 | * Inappropriate physical contact. You should have someone's consent before touching them.
41 | * Unwelcome sexual attention. This includes, sexualized comments or jokes; inappropriate touching, groping, and unwelcomed sexual advances.
42 | * Deliberate intimidation, stalking or following (online or in person).
43 | * Advocating for, or encouraging, any of the above behavior.
44 | * Sustained disruption of community events, including talks and presentations.
45 |
46 | ## 5. Weapons Policy
47 |
48 | No weapons will be allowed at Entity Framework Core.Data Encryption events, community spaces, or in other spaces covered by the scope of this Code of Conduct. Weapons include but are not limited to guns, explosives (including fireworks), and large knives such as those used for hunting or display, as well as any other item used for the purpose of causing injury or harm to others. Anyone seen in possession of one of these items will be asked to leave immediately, and will only be allowed to return without the weapon. Community members are further expected to comply with all state and local laws on this matter.
49 |
50 | ## 6. Consequences of Unacceptable Behavior
51 |
52 | Unacceptable behavior from any community member, including sponsors and those with decision-making authority, will not be tolerated.
53 |
54 | Anyone asked to stop unacceptable behavior is expected to comply immediately.
55 |
56 | If a community member engages in unacceptable behavior, the community organizers may take any action they deem appropriate, up to and including a temporary ban or permanent expulsion from the community without warning (and without refund in the case of a paid event).
57 |
58 | ## 7. Reporting Guidelines
59 |
60 | If you are subject to or witness unacceptable behavior, or have any other concerns, please notify a community organizer as soon as possible. .
61 |
62 |
63 |
64 | Additionally, community organizers are available to help community members engage with local law enforcement or to otherwise help those experiencing unacceptable behavior feel safe. In the context of in-person events, organizers will also provide escorts as desired by the person experiencing distress.
65 |
66 | ## 8. Addressing Grievances
67 |
68 | If you feel you have been falsely or unfairly accused of violating this Code of Conduct, you should notify with a concise description of your grievance. Your grievance will be handled in accordance with our existing governing policies.
69 |
70 |
71 |
72 | ## 9. Scope
73 |
74 | We expect all community participants (contributors, paid or otherwise; sponsors; and other guests) to abide by this Code of Conduct in all community venues--online and in-person--as well as in all one-on-one communications pertaining to community business.
75 |
76 | This code of conduct and its related procedures also applies to unacceptable behavior occurring outside the scope of community activities when such behavior has the potential to adversely affect the safety and well-being of community members.
77 |
78 | ## 10. Contact info
79 |
80 |
81 |
82 | ## 11. License and attribution
83 |
84 | The Citizen Code of Conduct is distributed by [Stumptown Syndicate](http://stumptownsyndicate.org) under a [Creative Commons Attribution-ShareAlike license](http://creativecommons.org/licenses/by-sa/3.0/).
85 |
86 | Portions of text derived from the [Django Code of Conduct](https://www.djangoproject.com/conduct/) and the [Geek Feminism Anti-Harassment Policy](http://geekfeminism.wikia.com/wiki/Conference_anti-harassment/Policy).
87 |
88 | _Revision 2.3. Posted 6 March 2017._
89 |
90 | _Revision 2.2. Posted 4 February 2016._
91 |
92 | _Revision 2.1. Posted 23 June 2014._
93 |
94 | _Revision 2.0, adopted by the [Stumptown Syndicate](http://stumptownsyndicate.org) board on 10 January 2013. Posted 17 March 2013._
95 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | ## Contributing of EntityFrameworkCore.DataEncryption
2 | To be added...
3 |
--------------------------------------------------------------------------------
/EntityFrameworkCore.DataEncryption.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{0F4B4CEC-5E5E-4CF0-9DCD-9C2E86802DCD}"
4 | EndProject
5 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sample", "sample", "{EFFA0BA3-FAFB-4EF6-920B-25BCBFE32B67}"
6 | EndProject
7 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{F093264A-3736-4863-B7B6-0786B929F9C4}"
8 | EndProject
9 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFrameworkCore.DataEncryption.Core", "src\EntityFrameworkCore.DataEncryption.Core\EntityFrameworkCore.DataEncryption.Core.csproj", "{3024BB69-3A96-4065-922C-8FD4B5E5E4E9}"
10 | EndProject
11 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFrameworkCore.DataEncryption.Conversions", "src\EntityFrameworkCore.DataEncryption.Conversions\EntityFrameworkCore.DataEncryption.Conversions.csproj", "{2F541FBE-A67C-4DCC-85DC-39C7A8DBDE3B}"
12 | EndProject
13 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{163CC7AB-9D74-4372-93F6-2FF05CA24536}"
14 | ProjectSection(SolutionItems) = preProject
15 | .gitignore = .gitignore
16 | README.md = README.md
17 | common.props = common.props
18 | EndProjectSection
19 | EndProject
20 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFrameworkCore.DataEncryption.Sample", "sample\EntityFrameworkCore.DataEncryption.Sample\EntityFrameworkCore.DataEncryption.Sample.csproj", "{72D12D0C-9300-4E31-8C0F-D5E4C241168E}"
21 | EndProject
22 | Global
23 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
24 | Debug|Any CPU = Debug|Any CPU
25 | Release|Any CPU = Release|Any CPU
26 | EndGlobalSection
27 | GlobalSection(NestedProjects) = preSolution
28 | {3024BB69-3A96-4065-922C-8FD4B5E5E4E9} = {0F4B4CEC-5E5E-4CF0-9DCD-9C2E86802DCD}
29 | {2F541FBE-A67C-4DCC-85DC-39C7A8DBDE3B} = {0F4B4CEC-5E5E-4CF0-9DCD-9C2E86802DCD}
30 | {72D12D0C-9300-4E31-8C0F-D5E4C241168E} = {EFFA0BA3-FAFB-4EF6-920B-25BCBFE32B67}
31 | EndGlobalSection
32 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
33 | {3024BB69-3A96-4065-922C-8FD4B5E5E4E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
34 | {3024BB69-3A96-4065-922C-8FD4B5E5E4E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
35 | {3024BB69-3A96-4065-922C-8FD4B5E5E4E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
36 | {3024BB69-3A96-4065-922C-8FD4B5E5E4E9}.Release|Any CPU.Build.0 = Release|Any CPU
37 | {2F541FBE-A67C-4DCC-85DC-39C7A8DBDE3B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
38 | {2F541FBE-A67C-4DCC-85DC-39C7A8DBDE3B}.Debug|Any CPU.Build.0 = Debug|Any CPU
39 | {2F541FBE-A67C-4DCC-85DC-39C7A8DBDE3B}.Release|Any CPU.ActiveCfg = Release|Any CPU
40 | {2F541FBE-A67C-4DCC-85DC-39C7A8DBDE3B}.Release|Any CPU.Build.0 = Release|Any CPU
41 | {72D12D0C-9300-4E31-8C0F-D5E4C241168E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
42 | {72D12D0C-9300-4E31-8C0F-D5E4C241168E}.Debug|Any CPU.Build.0 = Debug|Any CPU
43 | {72D12D0C-9300-4E31-8C0F-D5E4C241168E}.Release|Any CPU.ActiveCfg = Release|Any CPU
44 | {72D12D0C-9300-4E31-8C0F-D5E4C241168E}.Release|Any CPU.Build.0 = Release|Any CPU
45 | EndGlobalSection
46 | EndGlobal
47 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 Furkan Güngör
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ## Summary
2 |
3 | // PR Description is here
4 |
5 | ### Use-Case
6 |
7 | // Use-Case minimal document is here
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | ***
12 |
13 | ## Give a Star 🌟
14 | If you liked the project or if **EntityFrameworkCore.DataEncryption** helped you, please give a star.
15 |
16 | ***
17 |
18 | ### Purpose
19 | **EntityFrameworkCore.DataEncryption** with the entity framework core value converter feature, it allows you to store your data by encrypting it.
20 |
21 | ***
22 |
23 | ### Summary
24 |
25 | ```
26 | Install-Package EntityFrameworkCore.DataEncryption.Conversions
27 | ```
28 |
29 |
30 |
31 |
32 |
33 | Then mark the columns to be encrypted in DbContext.
34 |
35 |
36 |
37 |
38 |
39 | ```csharp
40 | protected override void OnModelCreating(ModelBuilder modelBuilder)
41 | {
42 | modelBuilder.Entity(entity =>
43 | {
44 | entity
45 | .Property(p => p.Id)
46 | .UseIdentityColumn();
47 | entity
48 | .Property(p => p.Name)
49 | .IsRequired()
50 | .HasMaxLength(2048);
51 |
52 | entity
53 | .Property(p => p.Surname)
54 | .IsRequired()
55 | .HasMaxLength(2048);
56 | entity
57 | .Property(p => p.Phone)
58 | .IsRequired()
59 | .HasConversion(new EncryptValueConverter(key:"89acMXSBpuEBDWHZ"));
60 | });
61 | base.OnModelCreating(modelBuilder);
62 | }
63 | ```
64 |
65 | ***
66 |
67 | ### Documentation
68 | Visit wiki documentation. [Wiki](https://github.com/furkandeveloper/EntityFrameworkCore.DataEncryption/wiki)
69 |
70 | ***
71 |
72 | ### Sample Project
73 |
74 | See for more information visit [sample project](https://github.com/furkandeveloper/EntityFrameworkCore.DataEncryption/tree/master/sample/EntityFrameworkCore.DataEncryption.Sample)
75 |
--------------------------------------------------------------------------------
/common.props:
--------------------------------------------------------------------------------
1 |
2 |
3 | net6.0
4 | 1.0.0
5 | latest
6 | false
7 | https://github.com/furkandeveloper/EntityFrameworkCore.DataEncryption
8 | furkandeveloper
9 | This package is a plugin that adds Data Encryption support to EntityFrameworkCore.
10 | encryption, entity-framework-core, ef-core
11 |
12 | ✨ Initial release
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/sample/EntityFrameworkCore.DataEncryption.Sample/Context/SampleDbContext.cs:
--------------------------------------------------------------------------------
1 | using EntityFrameworkCore.DataEncryption.Conversions;
2 | using EntityFrameworkCore.DataEncryption.Sample.Entities;
3 | using Microsoft.EntityFrameworkCore;
4 |
5 | namespace EntityFrameworkCore.DataEncryption.Sample.Context;
6 |
7 | ///
8 | /// Sample Db Context
9 | ///
10 | public class SampleDbContext : DbContext
11 | {
12 | ///
13 | /// protected ctor
14 | ///
15 | protected SampleDbContext()
16 | {
17 | }
18 |
19 | ///
20 | /// public ctor
21 | ///
22 | ///
23 | /// DbContext Options object.
24 | ///
25 | public SampleDbContext(DbContextOptions options) : base(options)
26 | {
27 | }
28 |
29 | public virtual DbSet Authors { get; set; }
30 |
31 | protected override void OnModelCreating(ModelBuilder modelBuilder)
32 | {
33 | modelBuilder.Entity(entity =>
34 | {
35 | entity
36 | .Property(p => p.Id)
37 | .UseIdentityColumn();
38 |
39 | entity
40 | .Property(p => p.Name)
41 | .IsRequired()
42 | .HasMaxLength(2048);
43 |
44 | entity
45 | .Property(p => p.Surname)
46 | .IsRequired()
47 | .HasMaxLength(2048);
48 |
49 | entity
50 | .Property(p => p.Phone)
51 | .IsRequired()
52 | .HasConversion(new EncryptValueConverter("89acMXSBpuEBDWHZ"));
53 | });
54 | base.OnModelCreating(modelBuilder);
55 | }
56 | }
--------------------------------------------------------------------------------
/sample/EntityFrameworkCore.DataEncryption.Sample/Controllers/AuthorController.cs:
--------------------------------------------------------------------------------
1 | using EntityFrameworkCore.DataEncryption.Sample.Context;
2 | using EntityFrameworkCore.DataEncryption.Sample.Entities;
3 | using Microsoft.AspNetCore.Mvc;
4 |
5 | namespace EntityFrameworkCore.DataEncryption.Sample.Controllers;
6 |
7 | [ApiController]
8 | [Route("[controller]")]
9 | public class AuthorController : ControllerBase
10 | {
11 | private readonly SampleDbContext _context;
12 |
13 | public AuthorController(SampleDbContext context)
14 | {
15 | _context = context;
16 | }
17 |
18 | [HttpGet("equal",Name = "Equal")]
19 | public Task EqualAsync([FromQuery]string phone)
20 | {
21 | return Task.FromResult(Ok(_context.Authors.Where(a=>a.Phone == phone).ToList()));
22 | }
23 | [HttpGet("contains",Name = "Contains")]
24 | public Task ContainsAsync([FromQuery]string phone)
25 | {
26 | return Task.FromResult(Ok(_context.Authors.Where(a=>a.Phone.Contains(phone)).ToList()));
27 | }
28 |
29 | [HttpPost(Name = "Insert")]
30 | public async Task InsertAsync([FromBody]Author author)
31 | {
32 | await _context.Authors.AddAsync(author);
33 | await _context.SaveChangesAsync();
34 | return NoContent();
35 | }
36 | }
--------------------------------------------------------------------------------
/sample/EntityFrameworkCore.DataEncryption.Sample/Entities/Author.cs:
--------------------------------------------------------------------------------
1 | namespace EntityFrameworkCore.DataEncryption.Sample.Entities;
2 |
3 | ///
4 | /// Author Entity
5 | ///
6 | public class Author
7 | {
8 | ///
9 | /// PK
10 | ///
11 | public int Id { get; set; }
12 |
13 | ///
14 | /// Name of Author
15 | ///
16 | public string Name { get; set; }
17 |
18 | ///
19 | /// Surname of Author
20 | ///
21 | public string Surname { get; set; }
22 |
23 | ///
24 | /// Phone of Author
25 | ///
26 | public string Phone { get; set; }
27 | }
--------------------------------------------------------------------------------
/sample/EntityFrameworkCore.DataEncryption.Sample/EntityFrameworkCore.DataEncryption.Sample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0
5 | enable
6 |
7 |
8 |
9 |
10 |
11 |
12 | all
13 | runtime; build; native; contentfiles; analyzers; buildtransitive
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/sample/EntityFrameworkCore.DataEncryption.Sample/Migrations/20220514214104_Initial.Designer.cs:
--------------------------------------------------------------------------------
1 | //
2 | using EntityFrameworkCore.DataEncryption.Sample.Context;
3 | using Microsoft.EntityFrameworkCore;
4 | using Microsoft.EntityFrameworkCore.Infrastructure;
5 | using Microsoft.EntityFrameworkCore.Migrations;
6 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
7 | using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
8 |
9 | #nullable disable
10 |
11 | namespace EntityFrameworkCore.DataEncryption.Sample.Migrations
12 | {
13 | [DbContext(typeof(SampleDbContext))]
14 | [Migration("20220514214104_Initial")]
15 | partial class Initial
16 | {
17 | protected override void BuildTargetModel(ModelBuilder modelBuilder)
18 | {
19 | #pragma warning disable 612, 618
20 | modelBuilder
21 | .HasAnnotation("ProductVersion", "6.0.4")
22 | .HasAnnotation("Relational:MaxIdentifierLength", 63);
23 |
24 | NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
25 |
26 | modelBuilder.Entity("EntityFrameworkCore.DataEncryption.Sample.Entities.Author", b =>
27 | {
28 | b.Property("Id")
29 | .ValueGeneratedOnAdd()
30 | .HasColumnType("integer");
31 |
32 | NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
33 |
34 | b.Property("Name")
35 | .IsRequired()
36 | .HasMaxLength(2048)
37 | .HasColumnType("character varying(2048)");
38 |
39 | b.Property("Phone")
40 | .IsRequired()
41 | .HasColumnType("text");
42 |
43 | b.Property("Surname")
44 | .IsRequired()
45 | .HasMaxLength(2048)
46 | .HasColumnType("character varying(2048)");
47 |
48 | b.HasKey("Id");
49 |
50 | b.ToTable("Authors");
51 | });
52 | #pragma warning restore 612, 618
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/sample/EntityFrameworkCore.DataEncryption.Sample/Migrations/20220514214104_Initial.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.EntityFrameworkCore.Migrations;
2 | using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
3 |
4 | #nullable disable
5 |
6 | namespace EntityFrameworkCore.DataEncryption.Sample.Migrations
7 | {
8 | public partial class Initial : Migration
9 | {
10 | protected override void Up(MigrationBuilder migrationBuilder)
11 | {
12 | migrationBuilder.CreateTable(
13 | name: "Authors",
14 | columns: table => new
15 | {
16 | Id = table.Column(type: "integer", nullable: false)
17 | .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
18 | Name = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: false),
19 | Surname = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: false),
20 | Phone = table.Column(type: "text", nullable: false)
21 | },
22 | constraints: table =>
23 | {
24 | table.PrimaryKey("PK_Authors", x => x.Id);
25 | });
26 | }
27 |
28 | protected override void Down(MigrationBuilder migrationBuilder)
29 | {
30 | migrationBuilder.DropTable(
31 | name: "Authors");
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/sample/EntityFrameworkCore.DataEncryption.Sample/Migrations/SampleDbContextModelSnapshot.cs:
--------------------------------------------------------------------------------
1 | //
2 | using EntityFrameworkCore.DataEncryption.Sample.Context;
3 | using Microsoft.EntityFrameworkCore;
4 | using Microsoft.EntityFrameworkCore.Infrastructure;
5 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
6 | using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
7 |
8 | #nullable disable
9 |
10 | namespace EntityFrameworkCore.DataEncryption.Sample.Migrations
11 | {
12 | [DbContext(typeof(SampleDbContext))]
13 | partial class SampleDbContextModelSnapshot : ModelSnapshot
14 | {
15 | protected override void BuildModel(ModelBuilder modelBuilder)
16 | {
17 | #pragma warning disable 612, 618
18 | modelBuilder
19 | .HasAnnotation("ProductVersion", "6.0.4")
20 | .HasAnnotation("Relational:MaxIdentifierLength", 63);
21 |
22 | NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
23 |
24 | modelBuilder.Entity("EntityFrameworkCore.DataEncryption.Sample.Entities.Author", b =>
25 | {
26 | b.Property("Id")
27 | .ValueGeneratedOnAdd()
28 | .HasColumnType("integer");
29 |
30 | NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
31 |
32 | b.Property("Name")
33 | .IsRequired()
34 | .HasMaxLength(2048)
35 | .HasColumnType("character varying(2048)");
36 |
37 | b.Property("Phone")
38 | .IsRequired()
39 | .HasColumnType("text");
40 |
41 | b.Property("Surname")
42 | .IsRequired()
43 | .HasMaxLength(2048)
44 | .HasColumnType("character varying(2048)");
45 |
46 | b.HasKey("Id");
47 |
48 | b.ToTable("Authors");
49 | });
50 | #pragma warning restore 612, 618
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/sample/EntityFrameworkCore.DataEncryption.Sample/Program.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Text.Json.Serialization;
3 | using EntityFrameworkCore.DataEncryption.Sample.Context;
4 | using Microsoft.EntityFrameworkCore;
5 |
6 | var builder = WebApplication.CreateBuilder(args);
7 |
8 | builder.Services.AddControllersWithViews().AddJsonOptions(options =>
9 | {
10 | options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
11 | });
12 |
13 | builder.Services.AddDbContext(options =>
14 | {
15 | options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection"));
16 | });
17 |
18 | // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
19 | builder.Services.AddEndpointsApiExplorer();
20 | builder.Services.AddSwaggerGen(options =>
21 | {
22 | options.SwaggerDoc("DataEncryption", new Microsoft.OpenApi.Models.OpenApiInfo()
23 | {
24 | Title = "EntityFrameworkCore.DataEncryption",
25 | Version = "1.0.0",
26 | Description = "This package is a plugin that adds Data Encryption support to EntityFrameworkCore.",
27 | Contact = new Microsoft.OpenApi.Models.OpenApiContact()
28 | {
29 | Email = "furkan.dvlp@gmail.com",
30 | Url = new Uri("https://github.com/furkandeveloper/EntityFrameworkCore.DataEncryption")
31 | }
32 | });
33 | var docFile = $"{Assembly.GetEntryAssembly()?.GetName().Name}.xml";
34 | var filePath = Path.Combine(AppContext.BaseDirectory, docFile);
35 |
36 | if (File.Exists((filePath)))
37 | {
38 | options.IncludeXmlComments(filePath);
39 | }
40 | options.DescribeAllParametersInCamelCase();
41 | });
42 |
43 | var app = builder.Build();
44 |
45 | if (app.Environment.IsDevelopment())
46 | {
47 | app.UseDeveloperExceptionPage();
48 | }
49 |
50 | app.UseRouting();
51 |
52 | app.UseSwagger();
53 |
54 | app.UseSwaggerUI(options =>
55 | {
56 | options.EnableDeepLinking();
57 | options.ShowExtensions();
58 | options.DisplayRequestDuration();
59 | options.DocExpansion(Swashbuckle.AspNetCore.SwaggerUI.DocExpansion.None);
60 | options.RoutePrefix = "api-docs";
61 | options.SwaggerEndpoint("/swagger/DataEncryption/swagger.json", "EasyProfilerSwagger");
62 | });
63 | app.MapControllers();
64 |
65 | app.MapDefaultControllerRoute();
66 |
67 | app.Run();
--------------------------------------------------------------------------------
/sample/EntityFrameworkCore.DataEncryption.Sample/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:55826",
7 | "sslPort": 44384
8 | }
9 | },
10 | "profiles": {
11 | "EntityFrameworkCore.DataEncryption.Sample": {
12 | "commandName": "Project",
13 | "dotnetRunMessages": true,
14 | "launchBrowser": true,
15 | "applicationUrl": "https://localhost:7254;http://localhost:5254",
16 | "environmentVariables": {
17 | "ASPNETCORE_ENVIRONMENT": "Development"
18 | }
19 | },
20 | "IIS Express": {
21 | "commandName": "IISExpress",
22 | "launchBrowser": true,
23 | "environmentVariables": {
24 | "ASPNETCORE_ENVIRONMENT": "Development"
25 | }
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/sample/EntityFrameworkCore.DataEncryption.Sample/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft.AspNetCore": "Warning"
6 | }
7 | },
8 | "AllowedHosts": "*"
9 | }
10 |
--------------------------------------------------------------------------------
/src/EntityFrameworkCore.DataEncryption.Conversions/EncryptValueConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq.Expressions;
3 | using EntityFrameworkCore.DataEncryption.Core;
4 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
5 |
6 | namespace EntityFrameworkCore.DataEncryption.Conversions;
7 |
8 | ///
9 | /// Encrypt Value Converter
10 | ///
11 | public class EncryptValueConverter : ValueConverter
12 | {
13 | private static string _password;
14 |
15 | public EncryptValueConverter(string key, ConverterMappingHints mappingHints = default)
16 | : base(EncryptExpr, DecryptExpr, mappingHints)
17 | {
18 | _password = key;
19 | }
20 |
21 | // from
22 | ///
23 | /// From Expression
24 | ///
25 | private static Expression> DecryptExpr => prop => Cipher.Decrypt(prop, _password);
26 |
27 | // to
28 | ///
29 | /// To Expression
30 | ///
31 | private static Expression> EncryptExpr => prop => Cipher.Encrypt(prop, _password);
32 | }
--------------------------------------------------------------------------------
/src/EntityFrameworkCore.DataEncryption.Conversions/EntityFrameworkCore.DataEncryption.Conversions.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/EntityFrameworkCore.DataEncryption.Conversions/encrypt.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/furkandeveloper/EntityFrameworkCore.DataEncryption/2a632820606d277c51029022347a7ea629035f38/src/EntityFrameworkCore.DataEncryption.Conversions/encrypt.png
--------------------------------------------------------------------------------
/src/EntityFrameworkCore.DataEncryption.Core/Cipher.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Security.Cryptography;
4 | using System.Text;
5 |
6 | namespace EntityFrameworkCore.DataEncryption.Core;
7 |
8 | ///
9 | /// Base Cipher class
10 | ///
11 | public static class Cipher
12 | {
13 | ///
14 | /// Encrypt a string.
15 | ///
16 | /// String to be encrypted
17 | /// Password
18 | public static string Encrypt(string plainText, string password)
19 | {
20 | // Get the bytes of the string
21 | var bytesToBeEncrypted = Encoding.UTF8.GetBytes(plainText);
22 | var passwordBytes = Encoding.UTF8.GetBytes(password);
23 |
24 | // Hash the password with SHA256
25 | passwordBytes = SHA256.Create().ComputeHash(passwordBytes);
26 |
27 | var bytesEncrypted = Cipher.Encrypt(bytesToBeEncrypted, passwordBytes);
28 |
29 | return Convert.ToBase64String(bytesEncrypted);
30 | }
31 |
32 | ///
33 | /// Decrypt a string.
34 | ///
35 | /// String to be decrypted
36 | /// Password used during encryption
37 | ///
38 | public static string Decrypt(string encryptedText, string password)
39 | {
40 | // Get the bytes of the string
41 | var bytesToBeDecrypted = Convert.FromBase64String(encryptedText);
42 | var passwordBytes = Encoding.UTF8.GetBytes(password);
43 |
44 | passwordBytes = SHA256.Create().ComputeHash(passwordBytes);
45 |
46 | var bytesDecrypted = Cipher.Decrypt(bytesToBeDecrypted, passwordBytes);
47 |
48 | return Encoding.UTF8.GetString(bytesDecrypted);
49 | }
50 |
51 | private static byte[] Encrypt(byte[] bytesToBeEncrypted, byte[] passwordBytes)
52 | {
53 | // Set your salt here, change it to meet your flavor:
54 | // The salt bytes must be at least 8 bytes.
55 | var saltBytes = new byte[] {1, 2, 3, 4, 5, 6, 7, 8};
56 |
57 | using var ms = new MemoryStream();
58 | using var aes = new RijndaelManaged();
59 | using var key = new Rfc2898DeriveBytes(passwordBytes, saltBytes, 1000);
60 | aes.KeySize = 256;
61 | aes.BlockSize = 128;
62 | aes.Key = key.GetBytes(aes.KeySize / 8);
63 | aes.IV = key.GetBytes(aes.BlockSize / 8);
64 |
65 | aes.Mode = CipherMode.CBC;
66 |
67 | using (var cs = new CryptoStream(ms, aes.CreateEncryptor(), CryptoStreamMode.Write))
68 | {
69 | cs.Write(bytesToBeEncrypted, 0, bytesToBeEncrypted.Length);
70 | cs.Close();
71 | }
72 |
73 | var encryptedBytes = ms.ToArray();
74 |
75 | return encryptedBytes;
76 | }
77 |
78 | private static byte[] Decrypt(byte[] bytesToBeDecrypted, byte[] passwordBytes)
79 | {
80 | // Set your salt here, change it to meet your flavor:
81 | // The salt bytes must be at least 8 bytes.
82 | var saltBytes = new byte[] {1, 2, 3, 4, 5, 6, 7, 8};
83 |
84 | using var ms = new MemoryStream();
85 | using var aes = new RijndaelManaged();
86 | using var key = new Rfc2898DeriveBytes(passwordBytes, saltBytes, 1000);
87 | aes.KeySize = 256;
88 | aes.BlockSize = 128;
89 | aes.Key = key.GetBytes(aes.KeySize / 8);
90 | aes.IV = key.GetBytes(aes.BlockSize / 8);
91 | aes.Mode = CipherMode.CBC;
92 |
93 | using (var cs = new CryptoStream(ms, aes.CreateDecryptor(), CryptoStreamMode.Write))
94 | {
95 | cs.Write(bytesToBeDecrypted, 0, bytesToBeDecrypted.Length);
96 | cs.Close();
97 | }
98 |
99 | var decryptedBytes = ms.ToArray();
100 |
101 | return decryptedBytes;
102 | }
103 | }
--------------------------------------------------------------------------------
/src/EntityFrameworkCore.DataEncryption.Core/EntityFrameworkCore.DataEncryption.Core.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/EntityFrameworkCore.DataEncryption.Core/encrypt.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/furkandeveloper/EntityFrameworkCore.DataEncryption/2a632820606d277c51029022347a7ea629035f38/src/EntityFrameworkCore.DataEncryption.Core/encrypt.png
--------------------------------------------------------------------------------