Hallo,

i'm working on an encryption methode for post-streams.
my J2ME device encrypt my content (using bouncy castle api) and send it to a php script which decrypt the post-stream. But my php script decrypt it into something useless.

-----------J2ME CODE-------------------------------------
private String key = "1234567890";
private String text = "Crypt this";

private String encryptText(String key, String text) throws CryptoException
{
byte[] keyBytes = Base64.decode(key.getBytes());
byte[] ptBytes = text.getBytes();

bfCipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new BlowfishEngine()));
bfCipher.init(true, new KeyParameter(keyBytes));
byte[] result = new byte[bfCipher.getOutputSize(ptBytes.length)];
int len = bfCipher.processBytes(ptBytes, 0, ptBytes.length, result, 0);
bfCipher.doFinal(result, len);

return new String(Base64.encode(result));
}//encryptText

private String decryptText(String key, String cipherText) throws CryptoException
{
byte[] keyBytes = Base64.decode(key.getBytes());
byte[] textBytes = Base64.decode(cipherText.getBytes());

bfCipher.init(false, new KeyParameter(keyBytes));
byte[] result = new byte[bfCipher.getOutputSize(textBytes.length)];
int len = bfCipher.processBytes(textBytes, 0, textBytes.length, result, 0);
bfCipher.doFinal(result, len);

return new String(result).trim();
}//decryptText
----------------------------------------------------------------
PHP CODE:

<?php
if (isset($_POST["test"])) { $test = $_POST["test"]; }

$iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_CBC);
$iv = "ha123"; //this isn't used in J2ME, don't know where to
//implement it
$key = "1234567890";
function strhex($string)
{
$hex="";
for ($i=0;$i<strlen($string);$i++)
$hex.=dechex(ord($string[$i]));
return $hex;
}
$textkey = strhex($key);
echo " hexkey: $textkey ";

echo " bevor: $test ";
$decrypt = mcrypt_decrypt(MCRYPT_BLOWFISH, $textkey, $test, MCRYPT_MODE_CBC, $iv);
echo " decrypt: $decrypt ";
flush();

?>

I hope you've an idea.
Thx for helping.