summaryrefslogtreecommitdiff
path: root/src/utils/CryptoUtils.scala
blob: 2b4d38e60e14f3b20004be156f2a2c792cb3bd1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package ixee.cryptopals.utils

import ixee.cryptopals.utils.crypto.CBCCipher
import javax.crypto.Cipher
import javax.crypto.spec.SecretKeySpec

object CryptoUtils {

  def pkcs7pad(s: String, blockSize: Int) = {
    val padLength = blockSize - (s.length % blockSize)
    s + s"${padLength.toChar}" * padLength
  }

  def cbcDecryptInstance(ecbCipher: Cipher, key: SecretKeySpec): CBCCipher = {
    ecbCipher.init(Cipher.DECRYPT_MODE, key)
    new CBCCipher(ecbCipher)
  }
}