title: Encrypt/Decrypt String Kotlin
body: <p>I've created this two extensions in Kotlin to Encrypt/Decrypt strings:</p>
  
  <pre><code>fun String.encrypt(seed : String): String {
      val keyGenerator = KeyGenerator.getInstance("AES")
      val secureRandom = SecureRandom.getInstance("SHA1PRNG")
      secureRandom.setSeed(seed.toByteArray())
  
      keyGenerator.init(128, secureRandom)
      val skey = keyGenerator.generateKey()
      val rawKey : ByteArray = skey.encoded
  
      val skeySpec = SecretKeySpec(rawKey, "AES")
      val cipher = Cipher.getInstance("AES/CBC/PKCS5Padding")
      cipher.init(Cipher.ENCRYPT_MODE, skeySpec)
      val byteArray = cipher.doFinal(this.toByteArray())
  
      return byteArray.toString()
  }
  
  fun String.decrypt(seed : String): String {
      val keyGenerator = KeyGenerator.getInstance("AES")
      val secureRandom = SecureRandom.getInstance("SHA1PRNG")
      secureRandom.setSeed(seed.toByteArray())
  
      keyGenerator.init(128, secureRandom)
      val skey = keyGenerator.generateKey()
      val rawKey : ByteArray = skey.encoded
  
      val skeySpec = SecretKeySpec(rawKey, "AES")
      val cipher = Cipher.getInstance("AES/CBC/PKCS5Padding")
      cipher.init(Cipher.DECRYPT_MODE, skeySpec)
      val byteArray = cipher.doFinal(this.toByteArray())
  
      return byteArray.toString()
  }
  </code></pre>
  
  <p>for some reason I'm getting the following exception:</p>
  
  <pre><code>javax.crypto.IllegalBlockSizeException: last block incomplete in decryption
  </code></pre>
  
  <p>What I'm doing wrong?</p>