Search Unity

System.Security.Cryptography.SHA256Cng not implemented

Discussion in 'Windows' started by seven_, Jan 17, 2019.

  1. seven_

    seven_

    Joined:
    Sep 30, 2014
    Posts:
    42
    Hi,

    I have been trying to integrate MSAL (Microsoft.Identity.Client) for some days now. Fighting several exceptions, and having found solutions, as to stripped code, I am now stuck.

    I am getting a NotSupportedException when the library tries to create a SHA256Cng object. I have looked into the created System.Core.dll, and yes, the constructor throws the exception. The original library is located in MonoBleedingEdge/lib/mono/unityaot, and also throws this exception.

    I am building with Il2CPP, .NET 4.x Equivalent, and Unity 2018.3.1. I have taken the Microsoft.Identity.Client.dll out of the latest NuGet package (2.7.0), folder net45.

    So, I am doing something wrong? Why is class SHA256Cng not implemented in the "unityaot version" of the dll? Any insights are highly appreciated!
     
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,937
    The unityaot profile is a bit smaller than other profile implementations to improve code size. So I don't think you are doing anything wrong.

    We could consider adding the SHA256Cng implementation to unityaot, although we'll need to balance that request with code size concerns. I'm not familiar with MSAL at all. Is there an option to use a different hashing algorithm?
     
  3. seven_

    seven_

    Joined:
    Sep 30, 2014
    Posts:
    42
    Thanks for getting back!
    The class is needed internally, so no I cannot change this.
    (I am not sure if the next class would be missing if SHA256Cng would be added.)
    Can I somehow just use some other implementation of yours (not unityaot), which implements SHA256Cng. If so, how do I do that?
     
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,937
    That probably depends on MSAL. If it requites SHA256Cng to be in System.Core.dll, then our only option is to consider adding it to the unityaot implementation. If MSAL has some option to bring your own hashing algorithm, then you might have an easier time replacing it.
     
  5. irfanK_21

    irfanK_21

    Joined:
    Jul 21, 2016
    Posts:
    2
    I am using Microsoft.IdentityModel.Clients.ActiveDirectory library for authentication and getting similar issue.
    NotSupportedException: System.Security.Cryptography.SHA256Cng

    Using Unity 2019.1.4f1, Scripting backend IL2CPP

    @seven_ Did you got any solution for this? I have used MSAL dll with unity and i am not facing any issues.
    Reference Link: https://peted.azurewebsites.net/microsoft-graph-auth-on-hololens/
     
  6. seven_

    seven_

    Joined:
    Sep 30, 2014
    Posts:
    42
    Thanks, no, we have not tried this further, and used some other authentication method instead.
     
  7. garrido86

    garrido86

    Joined:
    Dec 17, 2013
    Posts:
    233
    @seven_ what is the authentication method you have used?
    @JoshPeterson Do you know of maybe other workarounds get this working under IL2CPP?
     
  8. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,937
    I'm not aware of any work arounds, sorry.
     
  9. seven_

    seven_

    Joined:
    Sep 30, 2014
    Posts:
    42
    Probably not what you want to hear, but we are authenticating our users via their social network account now. This does not make all of them happy, but was the best compromise when also considering the work needed on our side.
     
    Last edited: Jul 14, 2020
  10. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    Which version of MSAL are you using? SHA256Cng is not part of .NET Standard 2.0. Any .NET Standard 2.0 DLLs will not be using it.
     
  11. garrido86

    garrido86

    Joined:
    Dec 17, 2013
    Posts:
    233
    I got around the issue by using the NETStandard version of the nugget package. I will setup in the future a github repo so people can see how it works.
     
  12. Gisornator

    Gisornator

    Joined:
    Nov 19, 2019
    Posts:
    2
    Hello @garrido86! Can you please elaborate how you could get arround that issue? We also used the nuget package but could only get the NET version to work (until we get the NotSupportedException). If we use the NETStandard version we get errors, that this assambly is not compatible.

    If you have a link to the github repo, I would highly appreciate it!
     
  13. Mixxit

    Mixxit

    Joined:
    Aug 28, 2013
    Posts:
    33