Unity3D content encryption protection and unity3d content Encryption
Only resources (Assets) can be protected by encryption during transmission, but the content may be obtained after data is transferred to the customer. For example, a tool can record 3D data at the driver level, allowing users to extract models and textures that are transmitted to the GPU. Therefore, we usually want users to meet their requirements when deciding to extract resources.
Of course, you can also use your own data encryption for the resource package (AssetBundle) file if you need it.
One way is to use the text Resource (AssetBundle) type to store data in bytes. You can encrypt data files and save them with the extension. bytes. Unity treats them as text resources (TextAsset. After being imported in the Editor, you can import the resource package (AssetBundle) that will be placed on the server as a text Resource (TextAssets) file ). You can download the resource package (AssetBundle) and decrypt the bytes stored in the text Resource (TextAsset) as the content. With this method, data is neither encrypted to the resource package (AssetBundles) nor saved as a text Resource (TextAssets.
string url = "http://www.mywebsite.com/mygame/assetbundles/assetbundle1.unity3d";IEnumerator Start () {// Start a download of the encrypted assetbundleWWW www = new WWW.LoadFromCacheOrDownload (url, 1);// Wait for download to completeyield return www;// Load the TextAsset from the AssetBundleTextAsset textAsset = www.assetBundle.Load("EncryptedData", typeof(TextAsset));// Get the byte databyte[] encryptedData = textAsset.bytes;// Decrypt the AssetBundle databyte[] decryptedData = YourDecryptionMethod(encryptedData);// Use your byte array.The AssetBundle will be cached}
Another method is to completely encrypt the resource package (AssetBundles) in the resource, and then use the WWW class to download the resource package. As long as the server provides binary data, it can be named by any file extension you like. After the download is complete, you can use. the decryption program related to bytes attribute data obtains the decrypted Resource Package (AssetBundle) file data and uses AssetBundle. createFromMemory creates a resource package (AssetBundle) in the memory ).
string url = "http://www.mywebsite.com/mygame/assetbundles/assetbundle1.unity3d";IEnumerator Start () {// Start a download of the encrypted assetbundleWWW www = new WWW (url);// Wait for download to completeyield return www;// Get the byte databyte[] encryptedData = www.bytes;// Decrypt the AssetBundle databyte[] decryptedData = YourDecryptionMethod(encryptedData);// Create an AssetBundle from the bytes arrayAssetBundle bundle = AssetBundle.CreateFromMemory(decryptedData);// You can now use your AssetBundle.The AssetBundle is not cached.}
The second method has the advantage of the first method in that bytes can be transmitted using any class function (except AssetBundles. LoadFromCacheOrDownload) and data can be fully encrypted-for example, sockets in the plug-in. The disadvantage is that the automatic cache function of Unity cannot be used for caching. You can use all players (except web players) to manually store files on disks and use AssetBundles. CreateFromFile to load files.
The third method combines the advantages of the first two methods to save the resource package (AssetBundle) as a text Resource (TextAsset) in other common resource packages ). The system caches unencrypted resource packages that contain the encrypted Resource Package (AssetBundle. Then, the original resource package (AssetBundle) is loaded into the memory and decrypted and instantiated using AssetBundle. CreateFromMemory.
string url = "http://www.mywebsite.com/mygame/assetbundles/assetbundle1.unity3d";IEnumerator Start () {// Start a download of the encrypted assetbundleWWW www = new WWW.LoadFromCacheOrDownload (url, 1);// Wait for download to completeyield return www;// Load the TextAsset from the AssetBundleTextAsset textAsset = www.assetBundle.Load("EncryptedData", typeof(TextAsset));// Get the byte databyte[] encryptedData = textAsset.bytes;// Decrypt the AssetBundle databyte[] decryptedData = YourDecryptionMethod(encryptedData);// Create an AssetBundle from the bytes arrayAssetBundle bundle = AssetBundle.CreateFromMemory(decryptedData);// You can now use your AssetBundle.The wrapper AssetBundle is cached}