Skip to content

Commit

Permalink
Merge pull request #34 from evolution-gaming/sandbox/jurisk/generate-…
Browse files Browse the repository at this point in the history
…private-key

Encrypt app should have a "feature" to generate a random privateKey
  • Loading branch information
t3hnar committed Jun 13, 2020
2 parents ab84009 + 50c492e commit 3dd11e7
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/main/scala/com/evolutiongaming/crypto/Encrypt.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package com.evolutiongaming.crypto

import scala.util.Random

object Encrypt extends App {
if (args.length != 2) {
println("Expected 2 arguments - value and privateKey")
if (args.length < 1 || args.length > 2) {
println("Expected 1 or 2 arguments - value and optional privateKey")
} else {
val value = args(0)
val privateKey = args(1)
val privateKey = args.lift(1) getOrElse {
val generated = Random.alphanumeric.take(16).mkString
println(s"privateKey wasn't provided and therefore a new privateKey was automatically generated: $generated")
generated
}

require(privateKey.length == 16, s"Expected privateKey to have 16 characters, got ${privateKey.length} characters instead")

val encrypted = Crypto.encryptAES(value, privateKey)
println(encrypted)
Expand Down

0 comments on commit 3dd11e7

Please sign in to comment.