Cannot find RIPEMD160 in .net core

Viewed 959

I can't find any implementation of RIPEMD160 in .net core 3.1.

The MS documentation for RIPEMD160 does not exist for net Standard, Core 3.1, Core 5.0 .

In System.Security.Cryptography I can't find nothing related to it.

Before looking to third party packages (maybe Chilkat) I'd like to try to use a framework library.

2 Answers

Microsoft decided to remove "managed" (fully implemented in .NET) implementations of hashing and crypto algorithms in .NET Core (don't ask me why). See for example https://github.com/dotnet/runtime/issues/2094 (that is exactly about RIPEMD160):

RIPEMD160 is not an algorithm that is provided by the OS crypto layers, and .NET Core no longer carries managed implementations of cryptographic algorithms.

And from msdn:

All hash algorithm and hash-based message authentication (HMAC) classes, including the *Managed classes, defer to the OS libraries. While the various OS libraries differ in performance, they should be compatible.

I can't find if there was a discussion about this, or if some manager decided that it was best to do in this way or what.

A simple solution is to grab the code used in .NET 4.7/.NET 4.8 and use it directly:

https://github.com/microsoft/referencesource/blob/master/mscorlib/system/security/cryptography/ripemd160managed.cs

The code is sourced as MIT, so there are no problems of licensing, see the homepage:

The files in this repository are licensed under the MIT license unless otherwise specified in the file header. If the file header only contains a copyright header (e.g., "Copyright (c) Microsoft Corporation. All rights reserved.", you can assume the associated file to be MIT-licensed.

I started to copy some classes from System.Security.Cryptography but because there are many attributes and dependencies on other classes/interfaces I don't like that solution.
Because Chilkat seems a little bit old (netstandard 1.3) and in the project I was already using BouncyCastle so in the end I just wrote this:

type RIPEMD160 () =
    static member ComputeHash (bytes: byte array) =
        let hasher =  Org.BouncyCastle.Crypto.Digests.RipeMD160Digest()
        hasher.BlockUpdate(bytes, 0, bytes.Length)
        let hash:byte array = Array.zeroCreate (hasher.GetDigestSize())
        hasher.DoFinal(hash, 0) |> ignore
        hash
Related