Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

ProtectedData.Protect IL2CPP issues

Discussion in 'Scripting' started by DougLuminous, Apr 16, 2019.

  1. DougLuminous

    DougLuminous

    Joined:
    Oct 19, 2018
    Posts:
    7
    When trying to call ProtectedData.Protect or ProtectedData.Unprotect in a Win32 build using IL2CPP I get the error "operation is not supported in this platform" but if I build for Win32 with Mono it works perfectly:

    Screen shot from the attached debugger for an IL2CPP build:


    Screen shot for an attached debugger for a Mono build of the same code:


    To get the code to compile at all I have added a csc.rsp file with the line -r:System.Security.dll. I have also tried link.xml files but without any luck. Any suggestions would be greatly appreciated before I create an issue on the issue tracker.

    I am only working on a Windows non UWP builds:
     

    Attached Files:

  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,787
    IL2CPP does not support all of the same parts of the class libraries as Mono support, and this is one of them. I'd recommend using the Mono scripting backend if this is something that you need.
     
  3. DougLuminous

    DougLuminous

    Joined:
    Oct 19, 2018
    Posts:
    7
    Oh dear, that is a bit of an inconvenience. Do you know if this is something that would be implemented later but in the meantime do you know of any alternatives or workarounds that I could consider?

    Thanks
     
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,787
    We will probably not be supporting these with IL2CPP, since the code in System.Security.Cryptography tends to pull in a large amount of managed code in a way that is not friendly to managed code stripping. This means that it will lead to large increases in output binary size on AOT platforms, even for project that don't make use of it.

    I'm not too familiar with the encryption library landscape, but you may be able to find third party libraries in native or managed code that can do this as well.
     
  5. manuelgoellnitz

    manuelgoellnitz

    Joined:
    Feb 15, 2017
    Posts:
    366
    Did you find an alternative?

    Since Unity 2021.2.12 or 13 the error occurs also on Windows.