unity夹克加密_Unity3D内容加密保护

仅管资源 (Assets) 在传输时可使用加密进行保护,但在数据流入客户手中后。其内容就有可能被获取。比如,有工具可记录驱动程序级别上的 3D 数据,同意用户提取传送至 GPU 的模型和纹理。

因此,我们通常希望在用户决定提取资源时。可以满足其要求。

当然,假设您须要。也能够对资源包 (AssetBundle) 文件使用自己的数据加密。

一种方法是,使用文本资源 (AssetBundle) 类型将数据存储为字节。您能够加密数据文件,并使用扩展名 .bytes 进行保存,Unity 会将其视为文本资源 (TextAsset) 类型。在编辑器 ( Editor) 中导入后。作为文本资源 (TextAssets) 的文件可导入将置于server上的资源包 (AssetBundle)。客户能够下载资源包 (AssetBundle) 并将存储在文本资源 (TextAsset) 中的字节解密为内容。借助此方法。既不会对资源包

(AssetBundles) 加密,又能够将数据作为文本资源 (TextAssets) 保存。

string url = "http://www.mywebsite.com/mygame/assetbundles/assetbundle1.unity3d";

IEnumerator Start () {

// Start a download of the encrypted assetbundle

WWW www = new WWW.LoadFromCacheOrDownload (url, 1);

// Wait for download to complete

yield return www;

// Load the TextAsset from the AssetBundle

TextAsset textAsset = www.assetBundle.Load("EncryptedData", typeof(TextAsset));

// Get the byte data

byte[] encryptedData = textAsset.bytes;

// Decrypt the AssetBundle data

byte[] decryptedData = YourDecryptionMethod(encryptedData);

// Use your byte array.The AssetBundle will be cached

}

还有一可用方法是对资源中的资源包 (AssetBundles) 全然加密。然后使用 WWW 类下载资源包。仅仅要server将其作为二进制数据提供 ,则可用不论什么您喜欢的文件扩展名命名。

下载完毕后。您能够使用 WWW 实例的 .bytes 属性数据相关的解密程序获取解密的资源包 (AssetBundle) 文件数据。并使用

AssetBundle.CreateFromMemory 在内存中创建资源包 (AssetBundle)。

string url = "http://www.mywebsite.com/mygame/assetbundles/assetbundle1.unity3d";

IEnumerator Start () {

// Start a download of the encrypted assetbundle

WWW www = new WWW (url);

// Wait for download to complete

yield return www;

// Get the byte data

byte[] encryptedData = www.bytes;

// Decrypt the AssetBundle data

byte[] decryptedData = YourDecryptionMethod(encryptedData);

// Create an AssetBundle from the bytes array

AssetBundle bundle = AssetBundle.CreateFromMemory(decryptedData);

// You can now use your AssetBundle.The AssetBundle is not cached.

}

另外一种方法之于第一种方法的优势在于。可使用不论什么类函数(AssetBundles.LoadFromCacheOrDownload 除外)传输字节,而且可对数据进行全然加密 – 比如。插件中的套接字。

缺点在于无法使用 Unity 的自己主动缓存功能进行缓存。

可使用全部播放器(网页播放器 (WebPlayer) 除外)在磁盘上手动存储文件,并使用

AssetBundles.CreateFromFile 载入文件。

第三种方法结合了前两种方法的长处,可将资源包 (AssetBundle) 另存为其它普通资源包中的文本资源 (TextAsset)。系统会缓存包括已加密资源包 (AssetBundle) 的未加密资源包。然后会将原始资源包 (AssetBundle) 载入到内存。并使用

AssetBundle.CreateFromMemory 解密并实例化。

string url = "http://www.mywebsite.com/mygame/assetbundles/assetbundle1.unity3d";

IEnumerator Start () {

// Start a download of the encrypted assetbundle

WWW www = new WWW.LoadFromCacheOrDownload (url, 1);

// Wait for download to complete

yield return www;

// Load the TextAsset from the AssetBundle

TextAsset textAsset = www.assetBundle.Load("EncryptedData", typeof(TextAsset));

// Get the byte data

byte[] encryptedData = textAsset.bytes;

// Decrypt the AssetBundle data

byte[] decryptedData = YourDecryptionMethod(encryptedData);

// Create an AssetBundle from the bytes array

AssetBundle bundle = AssetBundle.CreateFromMemory(decryptedData);

// You can now use your AssetBundle.The wrapper AssetBundle is cached

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值