Table of Contents

Class SHA1

Namespace
CryptoHives.Foundation.Security.Cryptography.Hash
Assembly
CryptoHives.Foundation.Security.Cryptography.dll

Computes the SHA-1 hash for the input data.

[Obsolete("SHA-1 is cryptographically weak and should not be used for security purposes.")]
public sealed class SHA1 : HashAlgorithm, ICryptoTransform, IDisposable, IResettable
Inheritance
SHA1
Implements
Inherited Members

Remarks

This is a fully managed implementation of SHA-1 based on FIPS 180-4. It does not rely on OS or hardware cryptographic APIs, ensuring deterministic behavior across all platforms and runtimes.

Security Warning: SHA-1 is cryptographically weak and should NOT be used for security purposes such as digital signatures or certificate verification. It is provided only for legacy compatibility.

Constructors

SHA1()

Initializes a new instance of the SHA1 class.

public SHA1()

Fields

BlockSizeBytes

The block size in bytes.

public const int BlockSizeBytes = 64

Field Value

int

HashSizeBits

The hash size in bits.

public const int HashSizeBits = 160

Field Value

int

HashSizeBytes

The hash size in bytes.

public const int HashSizeBytes = 20

Field Value

int

Properties

AlgorithmName

Gets the name of the hash algorithm.

public override string AlgorithmName { get; }

Property Value

string

BlockSize

Gets the block size in bytes used by the hash algorithm.

public override int BlockSize { get; }

Property Value

int

Methods

Create()

Creates a new instance of the SHA1 class.

public static SHA1 Create()

Returns

SHA1

A new SHA-1 hash algorithm instance.

Dispose(bool)

Releases the unmanaged resources used by the HashAlgorithm and optionally releases the managed resources.

protected override void Dispose(bool disposing)

Parameters

disposing bool

true to release both managed and unmanaged resources; false to release only unmanaged resources.

HashCore(ReadOnlySpan<byte>)

When overridden in a derived class, routes data written to the object into the hash algorithm for computing the hash.

protected override void HashCore(ReadOnlySpan<byte> source)

Parameters

source ReadOnlySpan<byte>

The input to compute the hash code for.

Exceptions

ObjectDisposedException

Thrown when the instance has been disposed.

HashData(ReadOnlySpan<byte>)

Computes the SHA-1 hash of source and returns it as a new byte array.

public static byte[] HashData(ReadOnlySpan<byte> source)

Parameters

source ReadOnlySpan<byte>

The input data to hash.

Returns

byte[]

A new byte array containing the SHA-1 hash.

Initialize()

Initializes an implementation of the HashAlgorithm class.

public override void Initialize()

Exceptions

ObjectDisposedException

Thrown when the instance has been disposed.

TryHashData(ReadOnlySpan<byte>, Span<byte>, out int)

Computes the SHA-1 hash of source and writes it into destination.

public static bool TryHashData(ReadOnlySpan<byte> source, Span<byte> destination, out int bytesWritten)

Parameters

source ReadOnlySpan<byte>

The input data to hash.

destination Span<byte>

The buffer to receive the hash value. Must be at least HashSizeBytes bytes.

bytesWritten int

When this method returns, the number of bytes written into destination.

Returns

bool

true if destination was large enough; otherwise, false.

TryHashFinal(Span<byte>, out int)

When overridden in a derived class, finalizes the hash computation and writes the result into the provided buffer.

protected override bool TryHashFinal(Span<byte> destination, out int bytesWritten)

Parameters

destination Span<byte>

The target buffer to write the hash to.

bytesWritten int

The number of bytes written into the buffer.

Returns

bool

true if the destination buffer was large enough; otherwise false.

Exceptions

ObjectDisposedException

Thrown when the instance has been disposed.