siss 0 Newbie Poster

Do anyone here knows flex builder?
I'm a beginner in this language. I have written a code for HMAC SHA1 signature generation for authenticating account in cloudstack. No error is showing while compiling. But when i run, the browser opens blank. The url is correct, the signature is genetated. I can see it in the url.But the orginal output is xml commands it is not showing. the page is simply left blank. Can anyone help me?
The code is as follows.

<fx:Script>
    <![CDATA[
        import com.adobe.crypto.HMAC;
        import com.adobe.crypto.SHA1;
        import com.adobe.utils.StringUtil;

        import flash.net.navigateToURL;

        import mx.controls.Alert;
        import mx.utils.Base64Encoder;
        import mx.utils.StringUtil;


        private var urlAPI:String;
        private var commandString:String;
        private var apiKey:String;
        private var apiKeyString:String;
        private var secretKey:String = "-kgkBuBUrGFeIC4gUvngSK_3Ypmi7fuF8XdVXIusnyyiEP2YUcG3FnPUGJGy3rp3Bw5ZNnqgS-9tIfyV1QnK1g";
        private var signature:String;
        private var urlRequestString:String

        [Bindable]
        private var encryptedString:String = "";

        [Bindable]
        private var encryptedByteArray:String = "";


        private function generateRequest():void
        {
            urlAPI = "http://10.176.14.26/client/api";
            commandString = "command=listZones";
            apiKey = "";
            apiKey = encodeURI(apiKey.toLowerCase());
            apiKeyString = "apiKey=" + apiKey;
            signature = generateSignature();
            urlRequestString = urlAPI +"?"+commandString+"&"+apiKeyString+"&signature="+signature;// "command=listZones&apiKey=Qo9Qwfatwz9ARB328Btn9PftzL2Cf5LOWd8OFyJmiM513tpTIm-zKxJoWkWqf353Df397xcLdKXGk8_JO8nM3Q&signature=Lxx1DM40AjcXU%2FcaiK8RAP0O1hU%3D";
            var urlRequestObj:URLRequest = new URLRequest(urlRequestString);
            navigateToURL(urlRequestObj,"_blank");
        }

        private function generateSignature():String
        {

            var tempSignature:String = apiKey +"&"+commandString;
            tempSignature = tempSignature.toLowerCase();

            return hashMessage(tempSignature,secretKey);

        }

        private function hashMessage(message:String, secretKey:String):String
        {           

            var algorithm:Object = SHA1;
            var encoder:Base64Encoder = new Base64Encoder();

            if(message.length > 0)

            {
                encryptedString = HMAC.hash(secretKey,message,algorithm);

                var messageBytes:ByteArray = new ByteArray();

                messageBytes.writeMultiByte(message,"utf-8");

                encryptedByteArray = HMAC.hashBytes(getByteArray(),messageBytes,algorithm);



                encoder.encode(encryptedByteArray); 


            }

            //Alert.show(encoder.toString());
            return encoder.toString();      
        }

        private var byteArray:ByteArray;

        [Bindable("dummyEventType")]
        private function  getByteArray():ByteArray
        {

            if(!byteArray)
            {
                byteArray = new ByteArray();
                byteArray.writeMultiByte(secretKey,"utf-8");
                //byteArray.


            }


            return byteArray;

        }   


        //http://10.176.14.26/client/api?command=listZones&apiKey=Qo9Qwfatwz9ARB328Btn9PftzL2Cf5LOWd8OFyJmiM513tpTIm-zKxJoWkWqf353Df397xcLdKXGk8_JO8nM3Q&signature=
        //http://10.176.14.26/client/api?command=listZones&apiKey=Qo9Qwfatwz9ARB328Btn9PftzL2Cf5LOWd8OFyJmiM513tpTIm-zKxJoWkWqf353Df397xcLdKXGk8_JO8nM3Q&signature=N2Y4NWU1N2E4ZjEyZGQ0ODJjOTFmZTM1OWMyMGEzZTMzMDYwMTMwMg== 





    ]]>
</fx:Script>
<s:Button x="102" y="64" label="Button" click="generateRequest()"/>
<ns1:CloudInterfaceComp x="196" y="213">
</ns1:CloudInterfaceComp>

</s:Application>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.