Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate SHA3-256 in .NET Core?

Is there an option to calculate SHA3-256 hashes in .NET Core? The goal is to recreate the isChecksumAddress util function in web3.js

like image 491
featherbits Avatar asked Dec 06 '17 16:12

featherbits


People also ask

Is SHA-3 the same as sha256?

​SHA-3 (and its variants SHA3-224, SHA3-256, SHA3-384, SHA3-512), is considered more secure than SHA-2 (SHA-224, SHA-256, SHA-384, SHA-512) for the same hash length. For example, SHA3-256 provides more cryptographic strength than SHA-256 for the same hash length (256 bits).

What SHA-3 256?

SHA3-256 belongs to the SHA-3 family of cryptographic hashes, as specified in FIPS 202. The hash function produces the 256 bit digest of a message: >>> from Crypto.Hash import SHA3_256 >>> >>> h_obj = SHA3_256.

How long is a SHA-3 256 hash?

SHA3-256 – hash is 256 bits long. SHA3-384 – hash is 384 bits long. SHA3-512 – hash is 512 bits long.

Is SHA-3 and sha512 same?

Nope. It's just a different construction. SHA3-512 is sponge while SHA-512 is Merkle-Damgard.


2 Answers

No, there is no way of doing that now with pure dotnet core.

It's been on the watch list since it was announced. Since we don't implement cryptographic algorithms within .NET we're waiting on support from the underlying platforms (Windows CNG, Apple Security.framework, and OpenSSL).

See this issue.

But you might have a better luck with BouncyCastle. It has an implementation here but I don't know if it is out yet (in nuget).

like image 113
pepo Avatar answered Sep 25 '22 00:09

pepo


FIPS-202 SHA3-256 (and all other SHA3 variants, e.g. SHA3-512, SHA3-SHAKE256) are implemented here, in pure .NET, with no dependencies on external APIs like BouncyCastle.

GitHub

https://github.com/series0ne/CORE/tree/master/Core/Security/Cryptography

Nuget

https://www.nuget.org/packages/SeriesOne.Core/

like image 22
Matthew Layton Avatar answered Sep 21 '22 00:09

Matthew Layton