Repository navigation
OnixLabs.Security.Cryptography.ReadOnlySpanExtensions
Provides extension methods for ReadOnlySpan<byte> instances, offering conversions into cryptographic primitive types defined in OnixLabs.Security.Cryptography.
| Namespace | OnixLabs.Security.Cryptography |
| Assembly | OnixLabs.Security.Cryptography.dll (NuGet) |
| Inheritance |
object → ReadOnlySpanExtensions
|
[EditorBrowsable(EditorBrowsableState.Never)]
public static class ReadOnlySpanExtensionsReadOnlySpanExtensions is a public static extension container decorated with [EditorBrowsable(EditorBrowsableState.Never)], which keeps the class itself out of IntelliSense lists while its extension methods remain fully usable on ReadOnlySpan<byte> receivers. Bring the methods into scope with using OnixLabs.Security.Cryptography;.
The class uses C# 14 extension blocks (extension(ReadOnlySpan<byte> receiver) { ... }), so the receiver type appears in the block declaration rather than as a this parameter. The signatures below are the call-site signatures as consumed by user code.
The conversion methods delegate to the implicit conversion operators defined on Hash and Secret respectively, providing a fluent, method-chain-friendly alternative to an explicit cast.
Note This
ReadOnlySpanExtensionsclass is the one in theOnixLabs.Security.Cryptographynamespace and contains only the two cryptographic-primitive conversion methods below. It is distinct from any similarly named extension class inOnixLabs.Core.
| Method | Returns | Description |
|---|---|---|
ToHash() |
Hash |
Converts the current ReadOnlySpan<byte> into a new Hash instance. |
ToSecret() |
Secret |
Converts the current ReadOnlySpan<byte> into a new Secret instance. |
public Hash ToHash()Converts the current ReadOnlySpan<byte> into a new Hash instance by implicitly converting the span.
Returns — A new Hash instance created from the current ReadOnlySpan<byte>.
using OnixLabs.Security.Cryptography;
ReadOnlySpan<byte> bytes = [0xde, 0xad, 0xbe, 0xef];
Hash hash = bytes.ToHash();public Secret ToSecret()Converts the current ReadOnlySpan<byte> into a new Secret instance by implicitly converting the span.
Returns — A new Secret instance created from the current ReadOnlySpan<byte>.
using OnixLabs.Security.Cryptography;
ReadOnlySpan<byte> keyMaterial = [0x00, 0x01, 0x02, 0x03];
Secret secret = keyMaterial.ToSecret();using System.Security.Cryptography;
using OnixLabs.Security.Cryptography;
byte[] raw = System.Text.Encoding.UTF8.GetBytes("Hello, World!");
using HashAlgorithm sha256 = SHA256.Create();
Hash hash = sha256.ComputeHash((ReadOnlySpan<byte>)raw).AsSpan().ToHash();
Console.WriteLine(hash);using OnixLabs.Security.Cryptography;
byte[] keyBytes = DeriveKeyMaterial();
Secret secret = ((ReadOnlySpan<byte>)keyBytes).ToSecret();ONIXLabs .NET Library · Repository · NuGet · License (Apache-2.0)
Copyright © ONIXLabs 2020. Licensed under the Apache License, Version 2.0.
- Enumeration<T>
- Optional<T>
- OptionalEqualityComparer<T>
- OptionalExtensions
- Result
- Result<T>
- ResultEqualityComparer<T>
- ResultExtensions
- Specification<T>
- Preconditions
- IValueEquatable<T>
- IValueComparable<T>
- IBinaryConvertible
- ISpanBinaryConvertible
- IMemoryBinaryConvertible
- ArrayExtensions
- ComparableExtensions
- DateTimeExtensions
- ISpanParsableExtensions
- ObjectExtensions
- RandomExtensions
- ReadOnlySequenceExtensions
- ReadOnlySpanExtensions
- StringExtensions
- Base16
- Base32
- Base58
- Base64
- IBaseCodec
- IBaseValue
- IBaseValue<T>
- Base16Codec
- Base32Codec
- Base58Codec
- Base64Codec
- Base16FormatProvider
- Base32FormatProvider
- Base58FormatProvider
- Base64FormatProvider
- EncodingExtensions
- ReadOnlySpanExtensions
- StringBuilderExtensions
- BigDecimal
- BigDecimalEqualityComparer
- BigDecimalOrdinalityComparer
- NumberInfo
- NumberInfoEqualityComparer
- NumberInfoOrdinalityComparer
- Int256
- Int512
- UInt256
- UInt512
- Float128
- Float256
- GenericMath
- NumericsExtensions
- ConversionMode
- ScaleMode
- Hash
- NamedHash
- Sha3
- Sha3Hash224
- Sha3Hash256
- Sha3Hash384
- Sha3Hash512
- Sha3Shake128
- Sha3Shake256
- MerkleTree
- MerkleTree<T>
- PrivateKey
- PublicKey
- NamedPrivateKey
- NamedPublicKey
- EcdhPrivateKey
- EcdhPublicKey
- EcdsaPrivateKey
- EcdsaPublicKey
- EddsaPrivateKey
- EddsaPublicKey
- RsaPrivateKey
- RsaPublicKey
- DigitalSignature
- DigitalSignatureAndPublicKey
- Salt
- Secret
- ICryptoPrimitive<T>
- IHashable
- IEcdhPrivateKey
- IEcdsaPrivateKey
- IEddsaPrivateKey
- IRsaPrivateKey
- IPrivateKeyDerivable<T>
- IPrivateKeyExportable
- IPrivateKeyImportable<T>
- IPrivateKeyPemImportable<T>
- IPrivateKeyPkcs8Exportable
- IPrivateKeyPkcs8Importable<T>
- IPrivateKeyPkcs8PemExportable
- IPrivateKeyRawExportable
- IPrivateKeyRawImportable<T>
- IPrivateKeyRawPemExportable
- IEcdhPublicKey
- IEcdsaPublicKey
- IEddsaPublicKey
- IRsaPublicKey
- IPublicKeyExportable
- IPublicKeyImportable<T>
- IPublicKeyPemExportable
- IPublicKeyPemImportable<T>
- IPublicKeyRawExportable
- IPublicKeyRawImportable<T>
- HashAlgorithmExtensions
- ReadOnlySpanExtensions