<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="TestXEnc.aspx.vb" Inherits="TestWebApp.TestXEnc"
    ValidateRequest="false" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Lizard Labs</title>
</head>
<body>
    <form id="form1" runat="server">
    <object id="oXEncXmlEncryptionComponent" classid="clsid:69AC1298-610C-4260-AB21-760698EA8513"
        style="display: none;" codebase="LizardLabsXEncLite.cab">
        An error occured during ActiveX installation. Please verify that:
        <ul>
            <li>your browser supports ActiveX.</li>
            <li>the ActiveX support in your browser has been enabled.</li>
            <li>that the path to proXSign cab within object tag is correct.</li>
        </ul>
    </object>

    <script language="javascript">

        function IsAxComponentInstalled(Class) 
        {
            try {
                var tmpo = new ActiveXObject(Class);
            }
            catch (e) {
            }

            if (tmpo == null) {
                return false;
            }
            else {
                tmpo = null;
                return true;
            }
        }

        function testencrypt() 
        {
            try 
            {
                if (IsAxComponentInstalled("LizardLabs.XEncLiteCtrl.1")) 
                {
                    alert("Installed");
                }
                else 
                {
                    alert("Not installed");
                    return false;
                }

                var oXEncXmlEncryptionComponent = document.getElementById("oXEncXmlEncryptionComponent")

                //oXEncXmlEncryptionComponent.Test("Test"); // test if control is loaded

                alert(document.getElementById("hiddenXml").value);

                oXEncXmlEncryptionComponent.UseLocalMachineStore = false; // Use users store (default)
                oXEncXmlEncryptionComponent.SystemSotreName = "My"; // Use persobnal store (default). Other possible values: My, Root, CA, OtherPeople...

                oXEncXmlEncryptionComponent.SelectCertificate();
                //oSignComponent.SelectCertificateByThumbprint("ae 3c 32 52 79 a8 eb 1d fd 8c ae 90 80 0f e2 57 7a d4 f2 6f");

                if (oXEncXmlEncryptionComponent.IsCertificateSelected()) {
                    if (oXEncXmlEncryptionComponent.Encrypt(document.getElementById("hiddenXml").value, "PaymentRq")) // Parameters: XML, ElementName (if you want to encrypt specific element within XML).
                    {
                        alert(oXEncXmlEncryptionComponent.EncryptedXml);
                        document.getElementById("hiddenSignedXml").value = oXEncXmlEncryptionComponent.EncryptedXml;

                        // Decrypt the document (this sample uses the private key for the same certificate that you have selected for encryption)
                        oXEncXmlEncryptionComponent.Decrypt(oXEncXmlEncryptionComponent.EncryptedXml); 
                        alert(oXEncXmlEncryptionComponent.DecryptedXml);

                        return true;
                    }
                    else alert("Error");
                }
                alert("Please select certificate!");
            }
            catch (e) {
                alert("JavaScript Error: " + e.message);
            }
            return false;
        }
    </script>

    <div>
        <h1>
            Lizard Labs: Test for XEnc XML encryption component)</h1>
        <asp:Button ID="Button1" runat="server" Text="Test" OnClientClick="return testencrypt();" />
        <input id="hiddenXml" type="hidden" runat="server" />
        <input id="hiddenSignedXml" type="hidden" runat="server" />
        <br />
        <br />
        <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~\Default.aspx">Back</asp:HyperLink>
        <p>
            If your browser settings support ActiveX installation, the XEnc Lite should be installed
            when opening this page in the Internet Explorer.</p>
        <p>
            <strong>XML:</strong></p>
        <asp:Label ID="lblXml" runat="server"></asp:Label>
        <p>
            <strong>Encrypted XML:</strong>
        </p>
        <asp:Label ID="lblEncryptedXml" runat="server"></asp:Label>
        <p>
            <strong>Decrypted result:</strong></p>
        <asp:Label ID="lblDecryptedXml" runat="server"></asp:Label>
    </div>
    </form>
</body>
</html>
