Search Unity

Question How to encrypt asset bundle

Discussion in 'Asset Bundles' started by vaibhavgoel2, Jul 23, 2021.

  1. vaibhavgoel2

    vaibhavgoel2

    Joined:
    Dec 3, 2020
    Posts:
    2
    Can you please us how to encrypt asset bundle & how to decrypt the same.
     
  2. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    304
    When you build the asset bundle into the file, encrypt the file itself.
    Before loading the asset bundle you can decrypt the file into temporary location or into memory and then load it with following method:

    AssetBundle.LoadFromFile
    or
    AssetBundle.LoadFromMemory

    About the encryption itself, you can google "C# encrypt byte array" or use CryptoStream (see MSDN docs).

    The question is, why would you like to do that? If you store decryption key in assembly itself or in memory, it won't be very hard to get it and then decrypt the bundles.

    The only good applicable use case I can think of is "pre-distributing" the content and providing the decryption key later (on the release day).