delightful-anonymization

delightful-anonymization is a Scala library for anonymizing case classes

License

License

GroupId

GroupId

org.sweet-delights
ArtifactId

ArtifactId

delightful-anonymization_2.13
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

delightful-anonymization
delightful-anonymization is a Scala library for anonymizing case classes
Project URL

Project URL

https://github.com/sweet-delights/delightful-anonymization
Project Organization

Project Organization

org.sweet-delights
Source Code Management

Source Code Management

https://github.com/sweet-delights/delightful-anonymization

Download delightful-anonymization_2.13

How to add to project

<!-- https://jarcasting.com/artifacts/org.sweet-delights/delightful-anonymization_2.13/ -->
<dependency>
    <groupId>org.sweet-delights</groupId>
    <artifactId>delightful-anonymization_2.13</artifactId>
    <version>0.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.sweet-delights/delightful-anonymization_2.13/
implementation 'org.sweet-delights:delightful-anonymization_2.13:0.1.0'
// https://jarcasting.com/artifacts/org.sweet-delights/delightful-anonymization_2.13/
implementation ("org.sweet-delights:delightful-anonymization_2.13:0.1.0")
'org.sweet-delights:delightful-anonymization_2.13:jar:0.1.0'
<dependency org="org.sweet-delights" name="delightful-anonymization_2.13" rev="0.1.0">
  <artifact name="delightful-anonymization_2.13" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.sweet-delights', module='delightful-anonymization_2.13', version='0.1.0')
)
libraryDependencies += "org.sweet-delights" % "delightful-anonymization_2.13" % "0.1.0"
[org.sweet-delights/delightful-anonymization_2.13 "0.1.0"]

Dependencies

compile (3)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.13.3
commons-codec : commons-codec jar 1.9
com.chuusai : shapeless_2.13 jar 2.3.3

provided (1)

Group / Artifact Type Version
org.scala-lang : scala-reflect jar 2.13.3

test (1)

Group / Artifact Type Version
org.specs2 : specs2-core_2.13 jar 4.5.1

Project Modules

There are no modules declared in this project.

Build Status Maven Central

delightful-anonymization is a library for anonymizing case classes on-the-fly.

This library is built for Scala 2.12.12 and 2.13.3

SBT

libraryDependencies += "org.sweet-delights" %% "delightful-anonymization" % "0.0.1"

Maven

<dependency>
  <groupId>org.sweet-delights</groupId>
  <artifactId>delightful-anonymization_2.12</artifactId>
  <version>0.0.1</version>
</dependency>

License

All files in delightful-anonymization are under the GNU Lesser General Public License version 3. Please read files COPYING and COPYING.LESSER for details.

How to anonymize a case class ?

Step 1: decorate a case class with @PII annotations. Example:

import sweet.delights.anonymization.PII
import sweet.delights.anonymization.Hash

case class Foo(
  opt: Option[String] @PII(Hash.MD5),
  str: String         @PII(Hash.SHA512),
  integer: Int
)

Step 2: apply the anonymize function on an instance of Foo:

import sweet.delights.anonymization.Anonymizer._

val foo = Foo(
  Some("opt"),
  "str",
  1
)

val anonymized == Foo(
  opt = Some("@-A9WeZjwa+awzqZSdEZNQWg=="),
  str = "@-Ms3snktf//qQkCS0pxCFDuLhtNPxn/2PJImMPoQBmZes+h+d3Q39yiEojcksp2agyxDgzXstaSbe/+zMWSOVAg==",
  integer = 1
)
//> true

Supported types

By default, Anonymizer hashes arrays of bytes. But any type T - other than products and co-products - that can be transformed into an array of bytes can be hashed.

The support for additional types is done via Injections, a mechanism borrowed from the frameless library.

For example, support for strings is added with the following:

import sweet.delights.anonymization.Injection
import org.apache.commons.codec.binary.Base64

lazy val anonymizedPrefix = "@:"

implicit lazy val stringInjection: Injection[String, Array[Byte]] = new Injection[String, Array[Byte]] {
  override def isAnonymized(t: String): Boolean = t.startsWith(anonymizedPrefix)
  override def apply(t: String): Array[Byte] = t.getBytes("UTF-8")
  override def invert(u: Array[Byte]): String = anonymizedPrefix + Base64.encodeBase64String(u)
}

Comments:

  • idempotence is achieved by calling the isAnonymized function. If it returns true then the value t is not re-hashed. Otherwise the specified hashing algorithm is applied.
  • it is up to the user to decide which injections are to be idempotent or not
  • the default hashing implementation of strings is idempotent

Supported hashing algorithms

The hashing algorithms are those supported by Java 8:

  • MD5
  • SHA-1
  • SHA-256
  • SHA-384
  • SHA-512

Other algorithms, not necessarly hashing algorithms, could be implemented. For instance, the anonymization method FirstLetter-of-a-string could be added. Contributions welcome!

Acknowledgments

org.sweet-delights

sweet-delights

A collection of libraries & tools.

Versions

Version
0.1.0
0.0.1