This project is read-only.

Exception Not implemented in reference assembly on OpenAlgorithm method

Oct 28, 2014 at 12:50 AM
I have added nuget package PCLCrypto into my PCL Project in VS 2013, so far so good.

When I go and test sample "Get the hash for a buffer (SHA1, SHA256, etc.)", throws an exception on line:

var hasher = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha1);

Exception:
"Not implemented in reference assembly."

My code:

public static string EncryptPassword(string strPassword)
    {


        UnicodeEncoding encoding = new UnicodeEncoding();
        byte[] bytEncPassword = encoding.GetBytes(strPassword);
        var hasher = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha1);
        byte[] hash = hasher.HashData(bytEncPassword);
        return Convert.ToBase64String(hash);
      }  
Please help.

Thanks in advance
Oct 29, 2014 at 1:54 PM
lachotorres wrote:
I have added nuget package PCLCrypto into my PCL Project in VS 2013, so far so good.

When I go and test sample "Get the hash for a buffer (SHA1, SHA256, etc.)", throws an exception on line:

var hasher = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha1);

Exception:
"Not implemented in reference assembly."

My code:

public static string EncryptPassword(string strPassword)
    {


        UnicodeEncoding encoding = new UnicodeEncoding();
        byte[] bytEncPassword = encoding.GetBytes(strPassword);
        var hasher = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha1);
        byte[] hash = hasher.HashData(bytEncPassword);
        return Convert.ToBase64String(hash);
      }  
Please help.

Thanks in advance
I am also seeing this error while unit testing an implementation.

Any help gratefully received.
Oct 30, 2014 at 7:49 PM
Install the PCLCrypto NuGet package in your platform-specific project as well. It's not enough to install it only in your PCL.
Oct 31, 2014 at 9:44 PM
I added PCL Crypto on my main Project and is working now!
Thanks for your help
Jan 16, 2015 at 9:22 AM
I have the same problem in my iOS project. When i try to use:
WinRTCrypto.AsymmetricKeyAlgorithmProvider.OpenAlgorithm (AsymmetricAlgorithm.RsaSignPkcs1Sha256).CreateKeyPair (4096);

i get "Not implemented in reference assembly" exception. My iOS project uses Unified Api. I tried to use almost every enum from AsymmetricAlgorithm and the result is the same - exception. Can anyone please help me?
Jan 19, 2015 at 3:54 PM
The fix for you is the same: use NuGet to install the package to your app project directly.

Jan 30, 2015 at 11:13 PM
Edited Jan 30, 2015 at 11:25 PM
This worked for me in my .NET web project. But when trying to add the NuGet package to my Android project, I got the following error:

Failed to add reference to 'Validation'.

Full output:
Attempting to resolve dependency 'Validation (≥ 2.0.5 && < 3.0)'.
'Validation 2.0.5.14286' already installed.
'PCLCrypto 0.5.2.14286' already installed.
Adding 'Validation 2.0.5.14286' to [ProjectName]
Failed to add reference to 'Validation'.
Trying to manually install through the Package Manager Console succeeds for Validation, but fails for PCLCrypto with this output:
PM> Install-Package PCLCrypto
Attempting to resolve dependency 'Validation (≥ 2.0.5 && < 3.0)'.
'PCLCrypto 0.5.2.14286' already installed.
Adding 'PCLCrypto 0.5.2.14286' to SVL.Dispatch.Mobile.Android.
Install-Package : Failed to add reference to 'PCLCrypto.Abstractions'.
At line:1 char:1
+ Install-Package PCLCrypto
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], InvalidOperationException
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand
Jan 31, 2015 at 6:13 PM
The Validation package seems to be present on nuget.org and in fact was 'already installed' per your log. I don't know why it would have failed. Perhaps try uninstalling the relevant packages and try to install again?

Feb 2, 2015 at 8:00 PM
AArnott wrote:
The Validation package seems to be present on nuget.org and in fact was 'already installed' per your log. I don't know why it would have failed. Perhaps try uninstalling the relevant packages and try to install again?
The "already installed" just refers to the fact that NuGet had downloaded the package to ($SolutionDir)\packages. The error was occurring when it was trying to add the reference to the project (in ..\packages\PCLCrypto.v\etc).

After some digging into the NuGet processes involved and the things can go wrong with them, I tracked the root down to a TFS issue, ultimately. Something about an incompatible pending change.

I had two solutions in the same directory. I had added PCLCrypto to the first one, and was having the issue with the second solution. It seems like in second solution, NuGet didn't know how to handle the fact that there was already a pending TFS change to add the package files it was trying to add to a solution that didn't reference them yet. I undid pending changes in the packages directory and was able to install both NuGet packages to the second solution and use the library without any problem.

Another potential solution would probably be to check in any pending changes first, after which NuGet could just prompt TFS check out any files it needed again as normal.
Feb 2, 2015 at 8:30 PM
Please file the NuGet bug you found on the MS Connect web site. But you should be advised that multiple solution files in the same directory, or multiple project files in the same directory, is strongly discouraged.

Feb 9, 2015 at 1:29 PM
I am having the same problem. I currently use the PCLCrypto in a "portable"-project where I generate a RSA public key and use the OpenAlgorithm functions throws a ""Not implemented in reference assembly.". If I add PCLCrypto to the main project it works. For me a point of having portable projects (shared) gets lost when I still have to reference it in the main project.

What is the status of this? Will it be fixed?

The API itself worked perfect. Was very easy to use and supplied me with the correct key. Good work AArnott :)
Feb 9, 2015 at 3:12 PM
Pettor, yes you have to install the NuGet Package into the app project itself -- not just the PCL. That's a limitation of NuGet's model right now and might be fixed in the future, but there's nothing PCLCrypto or any other PCL offering platform-specific functionality can do today to fix that.

I think you'll find there is still very much a point to this however. Your portable library which uses PCLCrypto can build and run on many platforms now. In fact if you ship your portable library as a NuGet package you can author in a dependency on PCLCrypto in your nuspec file and then everyone who installs your package into their mobile app Just Works.
It will be nice when installing it into the app project itself isn't necessary as a manual step though, I agree.

Feb 10, 2015 at 7:49 AM
Thank you for the reply AArnott. Didn't know about that limitation. Yes the point is of course that it will run on many platforms, which it does so this is indeed a small price to pay :)
Feb 10, 2015 at 2:20 PM
I am having same issue with xamarin ios project using unified API.
I have tried both PCL and shared projects.
I have added the NuGet package to all projects.
Same problem ("Not implemented in reference assembly")
Here is my code:
    public static string Encrypt(string textToEncrypt)
    {
        int iterations = 5000; // higher makes brute force attacks more expensive
        int keyLengthInBytes = 20;
        byte[] encryptedBytes = NetFxCrypto.DeriveBytes.GetBytes(textToEncrypt, salt, iterations, keyLengthInBytes);
        return Convert.ToBase64String(encryptedBytes);
    }
Please help.
Feb 10, 2015 at 5:15 PM
If you've installed the NuGet package in your iOS app project itself and still seeing this issue, it seems your build is copying the PCL reference assembly over the platform assembly. One possible workaround is installing this package into your iOS app project:

It adds build authoring to increase the odds of the right assembly being included in the app.

Feb 12, 2015 at 5:33 PM
I am having the same issue with an xamarin PCL project, using the unified API. The iOS project gets the "Not implemented in reference assembly" error. I have also added the Nuget package to all projects. (The SuppressPackagingPclFacades would not install.) Other posts have recommended setting the hintpath. I am looking at the Reference HintPath in the iOS.csproj file, and am unsure what it should hint to. Currently it is ...PCLCrypto.0.5.2.14286\lib\portable-net40+sl50+win+wpa81+wp80\PCLCrypto.dll (also for Abstractions). This is the same reference that the pcl project references. I tried changing to ...PCLCrypto.0.5.2.14286\lib\monotouch\PCLCrypto.dll, but it references monotouch which cannot be added with Xamarin.iOS unified API. What should the Xamarin.iOS project reference?
Feb 14, 2015 at 2:10 PM
Edited Feb 14, 2015 at 2:12 PM
I fixed my issue by editting the iOS project's .CSPROJ file with the following:

Was:
    <Reference Include="PCLCrypto.Abstractions">
      <HintPath>..\packages\PCLCrypto.0.5.2.14286\lib\portable-net40+sl50+win+wpa81+wp80\PCLCrypto.Abstractions.dll</HintPath>
    </Reference>
    <Reference Include="PCLCrypto">
      <HintPath>..\packages\PCLCrypto.0.5.2.14286\lib\portable-net40+sl50+win+wpa81+wp80\PCLCrypto.dll</HintPath>
    </Reference>
Changed To:
<Reference Include="PCLCrypto.Abstractions">
  <HintPath>..\packages\PCLCrypto.0.5.2.14286\lib\net40-Client\PCLCrypto.Abstractions.dll</HintPath>
</Reference>
<Reference Include="PCLCrypto">
  <HintPath>..\packages\PCLCrypto.0.5.2.14286\lib\net40-Client\PCLCrypto.dll</HintPath>
</Reference>
Feb 14, 2015 at 3:05 PM

PclCrypto.Abstractions? You have an old version. Have you tried upgrading?


Feb 14, 2015 at 4:04 PM
Thank you. I was pulling my hair out trying to figure out why I got the "not implemented" error. Changing the hint path worked.

@AArnott, Im not sure why your nuget doesnt install correctly for each platform but I havent had this problem with any other PCL nugets. Maybe look at what PCL Storage is doing as that works fine and follows the same pattern as yours.
Feb 14, 2015 at 4:39 PM

What version if pclcrypto did you install? What type of app project are you installing into that doesn't work?


Feb 17, 2015 at 4:18 PM
I believe I have the most current version, 0.5.2.14286, and I am working on a Xamarin.Forms PCL project with android and iOS projects. ebetzler's suggestion fixed the issue for me. Thank you!
Feb 17, 2015 at 4:26 PM
0.5.2 doesn't support iOS Unified. For that you need 1.0.0-beta2. Can you try upgrading to that and see if everything Just Works? If so, I can update that package to a stable release.

Feb 17, 2015 at 10:00 PM
Hi,
  I"m using MAC machine with Xamarin studio.  I've got an error  the same as ebetzler. Then I follow his solution to on this code:

<Reference Include="PCLCrypto.Abstractions">
<HintPath>..\packages\PCLCrypto.0.5.2.14286\lib\net40-Client\PCLCrypto.Abstractions.dll</HintPath>
</Reference>
<Reference Include="PCLCrypto">
<HintPath>..\packages\PCLCrypto.0.5.2.14286\lib\net40-Client\PCLCrypto.dll</HintPath>
</Reference>


After I changed it, when I compile. I've got this error below:
/Users/juny/Documents/XamarinProj/PDa/PDa/iOS/MTOUCHTASK: Error MT2002: Failed to resolve "System.Security.Cryptography.CngKey" reference from "System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" (MT2002) (PDa.iOS)

Please help.
Feb 18, 2015 at 3:45 PM
Can you please use 1.0.0-beta2 and tell me if you still have a problem? Also are you building an iOS Unified app?

Feb 18, 2015 at 4:18 PM
Hi AArnott,
    Xamarin Studio doesn't have a Package Manager Console.  I can't install the  1.0.0-beta2. 

    I can only add a packge thru a  Add Package window from Official Nugget Gallery which has  PCL Crypto.0.5.2.14286.

    I want to install the1.0.0-beta2 but I can't do it  Xamarin Studio on MAC machine.

    Please let me know if you have the latest on the Official Nugget Gallery.
Feb 18, 2015 at 4:24 PM

It is on the nuget.org gallery but it is an unstable package, so you have to indicate that you want to see unstable package in the UI that you're using.


Feb 20, 2015 at 1:20 PM
Now I am trying to deploy my build to a device, and am having the same problem as mcordz above:
"Failed to resolve "System.Security.Cryptography.CngKey"

I cannot install PCLCrypto 1.0.0-beta2 because it requires NUGET v2.8.3 and I have 2.8.1 (installed by Xamarin Studio on OSX).
Feb 24, 2015 at 3:15 PM
I'm having the same issue as ebetzler : The 'PCLCrypto 1.0.0-beta2' package requires NuGet client version '2.8.3' or above, but the current NuGet version is '2.8.1.0'.
Mar 8, 2015 at 5:14 AM
Can you upgrade to NuGet 2.8.3? Seems like a pretty simple thing to fix. :)
Update command line tool: nuget update -self
Or in VS: Tools -> Extensions & Updates -> Updates -> NuGet

May 15, 2015 at 8:48 PM
For me, running the most up-to-date everything that I could possibly find an update for, and using Xamarin Forms, going into my iOS project's references and switching the PCLCrypto reference to 'Copy Local: False' finally got things working for me. But I did not touch the reference in my regular shared project. Hope this helps someone else.

The weird thing was that the library worked great when I first installed it. Then I had to do battle with TFS and move the solution around multiple times. When I reopened the solution the error started to appear and stuck around even after reinstalling PCLCrypto.
Aug 17, 2015 at 6:27 PM
Just in case someone else finds this useful...

I had the same issue which I solved thanks to the post from @hvaughan3.

Setup:
  • Xamarin Studio 5.9.5 running in OSX (Mavericks)
  • PCLCrypto NuGet Package v1.0.2.15130
  • Created a PCL project with PCLCrypto and my implementation
  • Created NUnit Test Project referencing PCL library and added PCLCrypto.
Calling OpenAlgorithm in PCL caused System.NotImplementedException.

The solution was to untick "Local Copy" against the Reference to PCLCrypto in the Unit Test Project - and all works fine now.

HTH
Aug 25, 2015 at 5:16 AM
Edited Aug 25, 2015 at 7:57 AM
Hi,
I am having following problem,

I have installed PCLCrypto in all 4 projects(PCL /Android/Windows Phone 8.1/iOS) in my PCL project (Xamarin Forms).
When i chose TripleDes algorithm (any variant) it throws 'Algorithm not implemented' exception.
But it works well with Aes algorithms. I need to do TripleDes encryption to communicate with 3rd party server.

Anything am I missing ?

Update:
TripleDes working on Windows Phone 8.1 Project, But it failed as said above in Android.
Yet to test with iOS.

Env:
XF - 1.4.4
PCLCrypto -1.0.2.15130
Validation - 2.0.6
Sep 6, 2015 at 3:37 PM
@tnbsunwells, TripleDES isn't supported at present. I've opened #33 to track this.