简体   繁体   English

有没有一种方法可以将Adobe AIR(SWF / Flex)应用程序封装到C#应用程序中以使用HASP保护

[英]Is there a way to envelope Adobe AIR (SWF/Flex) application into C# application to use HASP protection

We have an Adobe AIR application which uses Flex Framework. 我们有一个使用Flex Framework的Adobe AIR应用程序。 It was initially built for browser version, but now we also need to use it as stand-alone application. 它最初是为浏览器版本构建的,但现在我们还需要将其用作独立应用程序。 This is possible to do using Adobe AIR. 使用Adobe AIR可以做到这一点。

However we need to use IP protection with this application, for our server side app we use SafeNet (formerly Alladin) HASP keys. 但是,我们需要在此应用程序中使用IP保护,对于我们的服务器端应用程序,我们使用SafeNet(以前称为Alladin)HASP密钥。 The same keys can be used for encrypting client stand-alone application, but set of languages supported by these keys is very limited and the easiest one would be C# (.NET). 可以使用相同的密钥来加密客户端独立应用程序,但是这些密钥支持的语言集非常有限,最简单的语言是C#(.NET)。

HASP protection works as follows: Execute encrypted binary, the decryption engine will check for USB key, if it is present the decryption mechanism written on key will decrypt the app into memory and execute it. HASP保护的工作方式如下:执行加密的二进制文件,解密引擎将检查USB密钥,如果存在,则写入密钥的解密机制会将应用解密到内存中并执行。

So the question is - what would be the best (easy and safe) way to embed SWF/AS files into C# app so these files will also be encrypted and therefore protected? 因此,问题是-将SWF / AS文件嵌入C#应用程序的最佳(简便,安全)方法是什么,以便这些文件也将被加密并因此受到保护?

PS: I've read other questions regarding this matter and there is no way to use HASP protection with AIR directly, but some questions imply that it is possible to use SWF apps from C# app through ActiveX container. PS:我已经阅读了有关此问题的其他问题,无法直接在AIR中使用HASP保护,但是有些问题暗示可以通过ActiveX容器从C#应用程序使用SWF应用程序。

PPS: Maybe that's a silly question, but I have no experience with C#, therefore any links, explanations, detailed instructions or examples will be appreciated. PPS:也许这是一个愚蠢的问题,但是我没有C#的经验,因此任何链接,解释,详细说明或示例都将不胜感激。

This will load an embedded swf resource as a binary memory stream right into a form-embedded Flash player COM object (without creating a temporary file). 这会将嵌入式swf资源作为二进制内存流加载到嵌入窗体的Flash Player COM对象中(无需创建临时文件)。 Please note that the capabilities of the SWF will be limited to the "standard" Flash Player sandbox, you cannot embed & run AIR swfs that use desktop/extendedDesktop in this way. 请注意,SWF的功能将限于“标准” Flash Player沙箱,您不能以这种方式嵌入和运行使用桌面/ extendedDesktop的AIR swf。

I've created a GitHub Project with the full code and a sample swf. 我已经用完整的代码和一个示例swf创建了一个GitHub Project

1) compile the AIR application as an SWF 1)将AIR应用程序编译为SWF

2) create a new C# Forms project 2)创建一个新的C#Forms项目

3) In the Solution Explorer, right-click on "References" and add "ShockWave Flash" from the COM tab 3)在解决方案资源管理器中,右键单击“参考”,然后从“ COM”选项卡中添加“ ShockWave Flash”

4) In the Solution Explorer, right-click on the project and select "Properties". 4)在解决方案资源管理器中,右键单击项目,然后选择“属性”。 Select the "Resources" tab in the newly opened form and add your SWF as a resource. 在新打开的表单中选择“资源”选项卡,然后将SWF添加为资源。

5) From the "General" tab in your Toolbox, drop a "ShockWave Flash" component on your form 5)从工具箱的“常规”选项卡中,在表单上放置一个“ ShockWave Flash”组件

6) Add the following code to your form: 6)将以下代码添加到表单中:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Reflection;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;

namespace SwfRes
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            LoadBinSwf();
        }

        private void LoadBinSwf()
        {
            //Assuming your swf is called "Main.swf"
            byte[] swf = Properties.Resources.Main;

            MemoryStream memStream = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(memStream);
            writer.Write(8 + swf.Length);
            writer.Write(0x55665566);
            writer.Write(swf.Length);
            writer.Write(swf);
            memStream.Seek(0, SeekOrigin.Begin);
            axShockwaveFlash1.OcxState = new AxHost.State(memStream, 1, false, null);
        }
    }
}

If all you want is to get your C# application encrypted with your swf/flex file, you can add the swf file to your C# application as an embedded resource. 如果只想用swf / flex文件加密C#应用程序,则可以将swf文件作为嵌入式资源添加到C#应用程序中。 That way you'll only have one executable file, and it will contain the swf application. 这样,您将只有一个可执行文件,并且它将包含swf应用程序。

When your C# application starts, you'll need to get the swf file and execute it (but it seems you know what to do here). 当您的C#应用​​程序启动时,您需要获取swf文件并执行该文件(但似乎您知道在这里做什么)。

Here is a tutorial about how to embed binary resources in your application and extract them at execution time: http://www.dotnetscraps.com/dotnetscraps/post/Insert-any-binary-file-in-C-assembly-and-extract-it-at-runtime.aspx 这是有关如何在应用程序中嵌入二进制资源并在执行时提取它们的教程: http : //www.dotnetscraps.com/dotnetscraps/post/Insert-any-binary-file-in-C-assembly-and-提取-IT-AT-runtime.aspx

You can compile AIR applications as a native executable. 您可以将AIR应用程序编译为本机可执行文件。 For windows (for example), that's .exe. 对于Windows(例如),就是.exe。 I imagine once you have compiled your AIR app for each platform natively, it should be easy to call/execute the AIR app from within C#. 我想,一旦您为每个平台本地编译了AIR应用程序,就可以轻松地从C#中调用/执行AIR应用程序。

The native installer (last I used it) was only available through the command line 本机安装程序(我上次使用它)仅通过命令行可用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM