public SHANativeHashProvider(string hashAlgorithmId)
        {
            Debug.Assert(HashProviderDispenser.CanUseSubtleCryptoImpl);

            switch (hashAlgorithmId)
            {
            case HashAlgorithmNames.SHA1:
                _impl            = SimpleDigest.Sha1;
                _hashSizeInBytes = 20;
                break;

            case HashAlgorithmNames.SHA256:
                _impl            = SimpleDigest.Sha256;
                _hashSizeInBytes = 32;
                break;

            case HashAlgorithmNames.SHA384:
                _impl            = SimpleDigest.Sha384;
                _hashSizeInBytes = 48;
                break;

            case HashAlgorithmNames.SHA512:
                _impl            = SimpleDigest.Sha512;
                _hashSizeInBytes = 64;
                break;

            default:
                throw new CryptographicException(SR.Format(SR.Cryptography_UnknownHashAlgorithm, hashAlgorithmId));
            }
        }
Esempio n. 2
0
        private static unsafe void SimpleDigestHash(SimpleDigest hashName, ReadOnlySpan <byte> data, Span <byte> destination)
        {
            fixed(byte *src = data)
            fixed(byte *dest = destination)
            {
                int res = Interop.BrowserCrypto.SimpleDigestHash(hashName, src, data.Length, dest, destination.Length);

                if (res != 0)
                {
                    throw new CryptographicException(SR.Format(SR.Unknown_SubtleCrypto_Error, res));
                }
            }
        }