@@ -396,8 +396,10 @@ iex(4)> Fields.Helpers.hash(:sha256, email)
396
396
17, 97, 146, 103, 115, 3, 185, 230, 137, 218, 137, 209, 111, 48, 236>>
397
397
` ` `
398
398
399
- The hash _value_ is identical for the given text.
400
- If you use the ` Fields.EmailHash` function,
399
+ The hash _value_ is identical for the given input text
400
+ in this case the the email address ` " [email protected] " ` .
401
+
402
+ If you use the ` Fields.EmailHash.dump/1` function,
401
403
you will see the same hash value
402
404
(_because the same helper function is invoked_):
403
405
@@ -412,8 +414,35 @@ iex(6)> Fields.EmailHash.dump(email)
412
414
17, 97, 146, 103, 115, 3, 185, 230, 137, 218, 137, 209, 111, 48, 236>>}
413
415
` ` `
414
416
417
+ When the ` EmailHash` is stored in a database
418
+ we can lookup an email address by hashing it
419
+ and comparing to the list.
420
+
421
+ The best way of _visualizing_ this
422
+ is to convert the hash value (bitstring)
423
+ to ` base64` so that it is _human-readable_:
424
+
425
+
426
+ ` ` ` elixir
427
+ iex(1)> email = "[email protected] "
428
+
429
+
430
+ iex(2)> Fields.Helpers.hash(:sha256, email) |> :base64.encode
431
+ "X/v7zLU77wTawSMU34PbZR4RYZJncwO55onaidFvMOw="
432
+
433
+ iex(3)> Fields.Helpers.hash(:sha256, email) |> :base64.encode
434
+ "X/v7zLU77wTawSMU34PbZR4RYZJncwO55onaidFvMOw="
435
+ ` ` `
436
+
437
+ Imagine you have a database table called ` people` that has just 3 columns: ` id` , ` email_hash` and ` email_encrypted`
415
438
416
439
440
+ | ` id` | ` email_hash` | ` email_encrypted` |
441
+ | ----- | ------------- | ----------------- |
442
+ | 1 | X/v7zLU77wTawSMU34PbZR4RYZJncwO55onaidFvMOw= | MDAwMc57Y1j0nhwOdw7EvNeUVEfYQoAr7aT6oX |
443
+ | 2 | +zXMhia/Z2I64nul6pqoDZTVM1q2K21Pby6GtPcm9iE= | MDAwMXnS1uwGN/cZRFkQgArm2Sbj9y+hnUJIS7 |
444
+ | 3 | maY4IxoRSOSqm6qyJDrnEN1JQssJRqRGhzwOown4DPU= | MDAwMa4v0FBko++zqfAkfisXOLosQfrDLAdPax |
445
+
417
446
418
447
< ! --
419
448
@@ -431,8 +460,9 @@ The `IV` is included in the `bitstring` returned by `AES.encrypt/1`
431
460
which could be split and stored separately in a high security system.
432
461
We are storing them together for now as we feel that having a unique key
433
462
stored in a Key Management System (KMS) is adequate for our needs.
434
- -- >
463
+
435
464
436
465
437
466
# ## How does
438
467
468
+ -->
0 commit comments