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

**URL:** <https://community.wowza.com/t/how-to-implement-tea-java-im-getting-java-lang-numberformatexception/37692>\
**Category:** Wowza Developer Dojo\
**Tags:** wowza-streaming-server-java-api\
**Created:** [November 27, 2011, 12:28pm UTC](https://community.wowza.com/t/how-to-implement-tea-java-im-getting-java-lang-numberformatexception/37692 "2011-11-27T12:28:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andy\_Saurin](https://avatars.discourse-cdn.com/v4/letter/a/c68b51/32.png) [@Andy\_Saurin](https://community.wowza.com/u/Andy_Saurin)\
**Post date:** [November 27, 2011, 12:28pm UTC](https://community.wowza.com/t/how-to-implement-tea-java-im-getting-java-lang-numberformatexception/37692/1 "2011-11-27T12:28:32Z")

</div>

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:

```auto
		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:

```auto
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: Æ÷}ÔÙ&#139;&#135;¢-Ïú*P&#134;&#152;
                                                                                                                          &#147;:.÷EE¢ª-JÔ8©õ&#153;þ&#150;¹iì&#159;&#154;©CT&#131;ûF*Ý&#145;;ÐÄ&#131;æð¥~ - - - 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:

```auto
    <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!!

---

<div class="post-metadata">

**Author:** ![Andy\_Saurin](https://avatars.discourse-cdn.com/v4/letter/a/c68b51/32.png) [@Andy\_Saurin](https://community.wowza.com/u/Andy_Saurin)\
**Post date:** [November 27, 2011, 12:36pm UTC](https://community.wowza.com/t/how-to-implement-tea-java-im-getting-java-lang-numberformatexception/37692/2 "2011-11-27T12:36:28Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Andy\_Saurin](https://avatars.discourse-cdn.com/v4/letter/a/c68b51/32.png) [@Andy\_Saurin](https://community.wowza.com/u/Andy_Saurin)\
**Post date:** [November 27, 2011, 1:47pm UTC](https://community.wowza.com/t/how-to-implement-tea-java-im-getting-java-lang-numberformatexception/37692/3 "2011-11-27T13:47:36Z")

</div>

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](http://code.google.com/p/beetle-j2ee-application-framework/source/browse/trunk/BJAFProject/1.5.x/testsrc/test/XXTEA.java?spec=svn71&r=66)

```auto
		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:

```auto
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…
