Repository navigation
Crypto
Home | API by Category | Complete API Index | API Status
| Field | Value |
|---|---|
| Full name | Electron2D.Crypto |
| Namespace | Electron2D |
| Kind | class |
| Category | API Networking |
Generates keys/certificates and performs RSA, digest-signature, HMAC and secure-random operations.
public class Electron2D.CryptoOperations/disposal require the constructing thread. Key operations import an independent BCL key snapshot under the resource lock and release it after the call. Generated resources are caller-owned. Key generation, import, asymmetric operations and copied results are cold work; prepared contexts handle streams.
Inherits: ElectronObject
Kind: constructor
public Crypto()Creates a cryptographic operation provider.
Kind: method
public System.Boolean ConstantTimeCompare(System.ReadOnlySpan<System.Byte> trusted, System.ReadOnlySpan<System.Byte> received)Compares equal-length byte strings without content-dependent early exit.
Lengths are public to the comparison; different lengths reject before comparing content.
True for equal bytes, including two empty spans; false for different lengths or content.
-
trusted: Trusted bytes. -
received: Received bytes.
Kind: method
public System.Byte[] Decrypt(Electron2D.CryptoKey key, System.ReadOnlySpan<System.Byte> ciphertext)Decrypts one modulus-sized RSA ciphertext using a private key and PKCS#1 v1.5 padding.
Caller-owned plaintext bytes.
-
key: Loaded private RSA key. -
ciphertext: One RSA ciphertext.
-
T:System.Security.Cryptography.CryptographicException: Key role, ciphertext length or padding is invalid.
Kind: method
public System.Byte[] Encrypt(Electron2D.CryptoKey key, System.ReadOnlySpan<System.Byte> plaintext)Encrypts one RSA plaintext using PKCS#1 v1.5 padding.
One modulus-sized ciphertext.
-
key: Loaded public or private RSA key. -
plaintext: At most modulus byte length minus eleven.
-
T:System.NotSupportedException: An EC key is supplied. -
T:System.Security.Cryptography.CryptographicException: The key or plaintext size is invalid.
Kind: method
public Electron2D.CryptoKey GenerateRSA(System.Int32 size)Generates a private RSA key resource.
A caller-owned canonical private key.
-
size: Key size in bits, subject to the current BCL provider's supported sizes.
-
T:System.Security.Cryptography.CryptographicException: Key size or generation is unsupported.
Kind: method
public System.Byte[] GenerateRandomBytes(System.Int32 size)Generates copied cryptographically secure random bytes.
A caller-owned array of the requested length.
-
size: Nonnegative requested byte count; zero is valid.
-
T:System.ArgumentOutOfRangeException: Size is negative.
Kind: method
public System.Void GenerateRandomBytes(System.Span<System.Byte> destination)Fills caller storage with cryptographically secure random bytes.
-
destination: Borrowed output storage, including an empty span.
Kind: method
public Electron2D.X509Certificate GenerateSelfSignedCertificate(Electron2D.CryptoKey key, System.String issuerName = "CN=myserver,O=myorganisation,C=IT", System.String notBefore = "20140101000000", System.String notAfter = "20340101000000")Generates a SHA-256 signed X.509 v3 self-signed CA certificate with path length zero.
A caller-owned certificate resource without private-key material.
-
key: Loaded RSA/EC private key, borrowed during the call. -
issuerName: Subject/issuer X.500 name containing nonempty CN, O and two-letter C. -
notBefore: First valid UTC instant as yyyyMMddHHmmss. -
notAfter: Last valid UTC instant in the same format, strictly later.
-
T:System.ArgumentException: Name or dates are invalid. -
T:System.Security.Cryptography.CryptographicException: A usable private key is unavailable.
Kind: method
public System.Byte[] HMACDigest(Electron2D.HashType hashType, System.ReadOnlySpan<System.Byte> key, System.ReadOnlySpan<System.Byte> message)Computes a complete HMAC-SHA1/HMAC-SHA256 message digest.
Caller-owned authentication bytes.
-
hashType: SHA1 or SHA256. -
key: Borrowed nonempty authentication key. -
message: Borrowed nonempty message bytes.
-
T:System.NotSupportedException: MD5 is selected. -
T:System.ArgumentException: Key or message is empty.
Kind: method
public System.Byte[] Sign(Electron2D.HashType hashType, System.ReadOnlySpan<System.Byte> hash, Electron2D.CryptoKey key)Signs a precomputed MD5/SHA1/SHA256 digest.
RSA PKCS#1 v1.5 or ECDSA DER signature bytes.
-
hashType: Digest identity. -
hash: Exactly 16, 20 or 32 bytes. -
key: Loaded private RSA/EC key.
-
T:System.ArgumentException: Digest length is invalid. -
T:System.Security.Cryptography.CryptographicException: The key or signing operation is invalid.
Kind: method
protected override System.Void ValidateDisposal()Verify(Electron2D.HashType, System.ReadOnlySpan<System.Byte>, System.ReadOnlySpan<System.Byte>, Electron2D.CryptoKey)
Kind: method
public System.Boolean Verify(Electron2D.HashType hashType, System.ReadOnlySpan<System.Byte> hash, System.ReadOnlySpan<System.Byte> signature, Electron2D.CryptoKey key)Verifies a precomputed digest and RSA PKCS#1/ECDSA DER signature.
False for a mismatched or malformed signature.
-
hashType: Digest identity. -
hash: Exactly the selected digest length. -
signature: Untrusted signature bytes. -
key: Loaded public or private RSA/EC key.
-
T:System.ArgumentException: The supplied digest has the wrong length.