How to implement TEA.java? I'm Getting java.lang.NumberFormatException

Hi all,

I’m trying desperately to implement TEA.java (from the security plugin) and I’m pretty sure I’ve got everything right up until I invoke TEA.decrypt()…

Here is my implementation:

		String streamName = httpCupertinoStreamingSession.getStreamName();
		getLogger().info("streamName: "+streamName);
		String decoded = new String(Base64.decode(streamName));
		getLogger().info("decoded: "+decoded);
		String unencryptedStreamName = TEA.decrypt(decoded, "MaryHadALittleLA");
		getLogger().info("unencryptedStreamName: " + unencryptedStreamName);

MaryHadALittleLA is the TEA key

However, when I run this, I get:

2011-11-27      21:21:00        CET     comment server  INFO    200     -       streamName: xvd91AbZi4eiLc/6oAZQhpgLkzougfcZRUWiqi1K1Dip9Zn+lrmNaeyfmqlDVIP7RiqBFd0GkTvQHsSD5vClfg==    -       -       -       0.281
 -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -
2011-11-27      21:21:00        CET     comment server  INFO    200     -       decoded: Æ÷}ÔÙ‹‡¢-Ïú*P†˜
                                                                                                                          “:.÷EE¢ª-JÔ8©õ™þ–¹i쟚©CTƒûF*Ý‘;Ðăæð¥~        -       -       -       0.282   -       -       -
 -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -
2011-11-27      21:21:00        CET     comment server  ERROR   500     -       invoke(onHTTPCupertinoStreamingSessionCreate): java.lang.NumberFormatException: For input string: "Æ÷": java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)   -       -       -       0.283   -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -

This is coming from a html5 video embed of:

    <video x-webkit-airplay="allow"  id="example_video_1" class="video-js" width="640" height="264" controls="controls" preload="auto" poster="http://video-js.zencoder.com/oceans-clip.png">
      <source src="http://<SERVER>:1935/<APP>/_definst_/xvd91AbZi4eiLc%2F6oAZQhpgLkzougfcZRUWiqi1K1Dip9Zn%2BlrmNaeyfmqlDVIP7RiqBFd0GkTvQHsSD5vClfg%3D%3D/playlist.m3u8" 
    </video>

the TEA encrypt has worked (it’s being passed in the URL as a base64 encoded string) since the values appear the same in the PHP tea decrypt output and the java decoded var. So, the problem is lying in

String unencryptedStreamName = TEA.decrypt(decoded, “MaryHadALittleLA”);

part…

ANY help greatly appreciated!!

relevant header:

import com.wowza.wms.httpstreamer.cupertinostreaming.httpstreamer.*;

import com.wowza.wms.module.*;

import com.wowza.wms.application.*;

import TEA;

import com.wowza.util.Base64;

and TEA.java is the one within the SecureToken plugin… as the source of the securetoken isn’t given, I can’t see how to implement TEA properly…

SOLVED

I implemented instead a different XXTEA class - http://code.google.com/p/beetle-j2ee-application-framework/source/browse/trunk/BJAFProject/1.5.x/testsrc/test/XXTEA.java?spec=svn71&r=66

		String decoded = new String(Base64.decode(streamName));
		getLogger().info("decoded: "+decoded);
		
		String reencoded = Base64.encodeBytes(Base64.decode(streamName));
		getLogger().info("base64Reencoded: "+reencoded);
		byte[] key = "MaryHadALittle".getBytes();
		byte[] streamNameBytes = Base64.decode(streamName);
		String unencryptedStreamName = new String(XXTEA.decrypt(streamNameBytes, key));
		getLogger().info("unencryptedStreamName: " + unencryptedStreamName);

which gave:

2011-11-27      22:41:10        CET     comment server  INFO    200     -       decoded: &#146;&#151;ýÚÙ&ö&#158;;»¼µÐ\Öú,&#138;v®Ëç=ÙÚ(\Ì°Ááh·&#146;Gáà=¢PÙ
                                                                                                                                                     ýFK[&#138;W            -       -       -       0.271   -       -       -       -
 -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -
2011-11-27      22:41:10        CET     comment server  INFO    200     -       base64Reencoded: kpcP/drZJgX2BZ47u7y10FzW+iyKdq7L5z3Z2ihczLDB4Wi3AJJH4eA9G9eiUNkM/UZLAVuKVwk=   -       -       -       0.272   -
 -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -
2011-11-27      22:41:10        CET     comment server  INFO    200     -       unencryptedStreamName: RoboCupSoccer_Robot_Football_at_2009_German_Open.mp4     -       -       -       0.273   -       -       -

Wooohoooo!

Just putting up my solution for those that come across the same problem…