Apache-2.0 license Build Status Download

data-security

This Library has been merged with application-utilities and will no longer be maintained

Mechanisms for encrypting and decrypting data

To utilise this library add this to your sbt build file

"com.cjww-dev.libs" % "data-security_2.11" % "2.7.0" 

About

DataSecurity.scala

encryptType
Takes a parameter of type T and an implicit Json Writes[T] and returns an encrypted String.

Example

    case class ExampleCaseClass(str: String, int: Int)
    
    implicit val writer = Json.writes[ExampleCaseClass]

    val encString: String = DataSecurity.encryptType[ExampleCaseClass](ExampleCaseClass("exp", 616))

decryptIntoType
Takes an encrypted String parameter and an implicit Json Reads[T] and returns a T.

Example

    case class ExampleCaseClass(str: String, int: Int)
    
    implicit val writer = Json.reads[ExampleCaseClass]

    val string: ExampleCaseClass = DataSecurity.decryptIntoType[ExampleCaseClass]("ENCRYPTED_STRING")

encryptString
Takes a String parameter and returns an encrypted String.

Example

    val string: String = DataSecurity.encryptString("string")

decryptString
Takes an encrypted String parameter and returns a String.

Example

    val string: String = DataSecurity.decryptString("ENCRYPTED_STRING")

SHA512.scala

Unlike DataSecurity the function in SHA512 in not reversible.

encrypt
Takes a String parameter and returns an encrypted String.

Example

    val string: String = SHA512.encrypt("string")

Configuration

Add this config to your conf/application.conf file in your scala play project.

    microservice {
      data-security {
        key  = ""
        salt = ""
      }
    }

License

This code is open source software licensed under the Apache 2.0 License