title: IllegalBlockSizeException "Invalid input length" when decrypt data
body: <p>I am developing an android app.</p>
  
  <p>I want to encrypt/decrypt some sensitive data (jwt token) into SharedPreference.</p>
  
  <p>So I wrote the below code.</p>
  
  <pre><code>fun initKeyStore() {
      val alias = "${packageName}.rsakeypairs"
      val keyStore = KeyStore.getInstance("AndroidKeyStore").apply {
          load(null)
      }
  
      if (keyStore.containsAlias(alias)) {
  
      } else {
          SLog.d(LogTag.SECURE, "[cipher] No keypair for $alias, creating a new one")
          with(KeyPairGenerator.getInstance(KEY_ALGORITHM_RSA, "AndroidKeyStore"), {
              val spec = KeyGenParameterSpec.Builder(alias,
                      PURPOSE_ENCRYPT or PURPOSE_DECRYPT)
                      .setAlgorithmParameterSpec(RSAKeyGenParameterSpec(2048, RSAKeyGenParameterSpec.F4))
                      .setBlockModes(BLOCK_MODE_CBC)
                      .setEncryptionPaddings(ENCRYPTION_PADDING_RSA_PKCS1)
                      .setDigests(DIGEST_SHA512, DIGEST_SHA384, DIGEST_SHA256)
                      .setUserAuthenticationRequired(false)
                      .build()
              initialize(spec)
              generateKeyPair()
          })
      }
  
      keyEntry = keyStore.getEntry(alias, null)
  }
  
  fun String.encrypt(): String? {
      cipher.init(Cipher.ENCRYPT_MODE, (keyEntry as KeyStore.PrivateKeyEntry).certificate.publicKey)
      val bytes = this.toByteArray(Charsets.UTF_8)
      val encryptedBytes = cipher.doFinal(bytes)
      val base64EncryptedBytes = Base64.encode(encryptedBytes, Base64.DEFAULT)
      return String(base64EncryptedBytes)
  }
  
  fun String.decrypt(): String {
      cipher.init(Cipher.DECRYPT_MODE, (keyEntry as KeyStore.PrivateKeyEntry).privateKey)
      val base64EncryptedBytes = this.toByteArray(Charsets.UTF_8)
      val encryptedBytes = Base64.decode(base64EncryptedBytes, Base64.DEFAULT)
      val decryptedBytes = cipher.doFinal(encryptedBytes)
      return String(decryptedBytes)
  }
  
  </code></pre>
  
  <p>But when the app tries to decrypt the encrypted data, Exception occurred.</p>
  
  <pre><code>    javax.crypto.IllegalBlockSizeException
          at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:513)
          at javax.crypto.Cipher.doFinal(Cipher.java:2055)
          ...
       Caused by: android.security.KeyStoreException: Invalid input length
          at android.security.KeyStore.getKeyStoreException(KeyStore.java:1539)
          at android.security.keystore.KeyStoreCryptoOperationChunkedStreamer.update(KeyStoreCryptoOperationChunkedStreamer.java:132)
  </code></pre>
  
  <p>The length of the JWT token that I am using is very long. (More than 800)</p>
  
  <p>If I try to encrypt/decrypt short text, it works fine...</p>
  
  <p>How can I encrypt/decrypt the long text?</p>