Scala中此加密和解密代码的等价物是什么?

$KEY = "Your KEY";
$IV = "Your IV";

function addpadding($string, $blocksize = 32)
{
    $len = strlen($string);
    $pad = $blocksize - ($len % $blocksize);
    $string .= str_repeat(chr($pad), $pad);
    return $string;
}

function strippadding($string)
{
    $slast = ord(substr($string, -1));
    $slastc = chr($slast);
    $pcheck = substr($string, -$slast);
    if(preg_match("/$slastc{".$slast."}/", $string)){
        $string = substr($string, 0, strlen($string)-$slast);
        return $string;
    } else {
        return false;
    }
}

function encrypt($string = "")
{
    global $KEY,$IV;
    $key = base64_decode($KEY);
    $iv = base64_decode($IV);
    return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key,  addpadding($string), MCRYPT_MODE_CBC, $iv));
}

function decrypt($string = "")
{
    global $KEY,$IV;
    $key = base64_decode($KEY);
    $iv = base64_decode($IV);
    $string = base64_decode($string);
    return strippadding(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $string, MCRYPT_MODE_CBC, $iv));
}

EDIT

I'm looking for the exact implementation not just references to libraries so I posted the answer by myself. I'm coding in Scala but at first I asked for Java to increase the chance of getting an answer as quickly as possible, so the implementation is in Scala language.

Thanks to the comments, here is the Scala implementation which works exactly the same as the above PHP code:

import org.apache.commons.codec.binary.Base64
import org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher
import org.bouncycastle.crypto.modes.CBCBlockCipher
import org.bouncycastle.crypto.engines.RijndaelEngine
import org.bouncycastle.crypto.paddings.PKCS7Padding
import org.bouncycastle.crypto.params._

class EncryptionUtil(keyBase64: String, ivBase64: String) {
  private val keyBytes = Base64.decodeBase64(keyBase64)
  private val ivBytes = Base64.decodeBase64(ivBase64)

  def encrypt(message: String): String = {
    val cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new RijndaelEngine(256)), new PKCS7Padding());
    val keySize = keyBytes.length;
    val ivAndKey = new ParametersWithIV(new KeyParameter(keyBytes, 0, keySize), ivBytes, 0, keySize);
    cipher.init(true, ivAndKey);
    val messageBytes = message.getBytes("UTF-8")
    val encrypted  = new Array[Byte](cipher.getOutputSize(messageBytes.length));
    val oLen = cipher.processBytes(messageBytes, 0, messageBytes.length, encrypted, 0);
    cipher.doFinal(encrypted, oLen);
    Base64.encodeBase64String(encrypted)
  }

  def decrypt(inputBase64: String): String = {
    val cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new RijndaelEngine(256)), new PKCS7Padding());
    val keySize = keyBytes.length;
    val ivAndKey = new ParametersWithIV(new KeyParameter(keyBytes, 0, keySize), ivBytes, 0, keySize);
    cipher.init(false, ivAndKey);
    val messageBytes = Base64.decodeBase64(inputBase64)
    val decrypted  = new Array[Byte](cipher.getOutputSize(messageBytes.length));
    val oLen = cipher.processBytes(messageBytes, 0, messageBytes.length, decrypted, 0);
    cipher.doFinal(decrypted, oLen);

    val zeroTerminationIndex = decrypted.indexOf(0)
    new String(decrypted, 0, zeroTerminationIndex, "UTF-8")
  }
}

object EncryptionUtil {
  def apply(keyBase64: String, ivBase64: String) = new EncryptionUtil(keyBase64, ivBase64)
}

It uses bouncycastle which can be added to build.sbt:

libraryDependencies += "org.bouncycastle" % "bcprov-jdk15on" % "1.52"