Class CryptoException
Exception thrown by ScyllaCrypto and the internal provider layer when a cryptographic operation fails. Carries a structured ErrorCode value of type CryptoErrorCode that identifies the specific failure category, enabling callers to distinguish between, for example, a wrong-key authentication failure and an unsupported-platform error without parsing the message string.
Implements
Inherited Members
Namespace: Scylla.Core.Util.Crypto
Assembly: ScyllaCore.dll
Syntax
public class CryptoException : Exception, ISerializable
Remarks
In most cases, prefer the non-throwing TryDecrypt overloads
(TryDecrypt(byte[], string, out byte[])) when
decryption failure is an expected outcome (e.g., probing with a user-entered
password). Reserve try/catch on CryptoException for infrastructure
paths where failure is unexpected.
When catching this exception, always inspect ErrorCode first to distinguish recoverable situations (e.g., AuthenticationFailed - prompt for a new password) from non-recoverable ones (e.g., UnsupportedAlgorithm - reconfigure the algorithm).
try
{
var plaintext = ScyllaCrypto.Decrypt(ciphertext, password);
// use plaintext...
}
catch (CryptoException ex) when (ex.ErrorCode == CryptoErrorCode.AuthenticationFailed)
{
// Wrong password or tampered data - prompt the user to try again.
Debug.LogWarning("Decryption failed: wrong password.");
}
catch (CryptoException ex) when (ex.ErrorCode == CryptoErrorCode.UnsupportedAlgorithm)
{
// Platform does not support the selected algorithm.
Debug.LogError($"Algorithm not available: {ex.Message}");
}
Constructors
CryptoException(CryptoErrorCode)
Initializes a new instance of CryptoException with the specified error code.
Declaration
public CryptoException(CryptoErrorCode errorCode)
Parameters
| Type | Name | Description |
|---|---|---|
| CryptoErrorCode | errorCode | The error code indicating the type of failure. |
CryptoException(CryptoErrorCode, string)
Initializes a new instance of CryptoException with the specified error code and message.
Declaration
public CryptoException(CryptoErrorCode errorCode, string message)
Parameters
| Type | Name | Description |
|---|---|---|
| CryptoErrorCode | errorCode | The error code indicating the type of failure. |
| string | message | The error message that explains the reason for the exception. |
CryptoException(CryptoErrorCode, string, Exception)
Initializes a new instance of CryptoException with the specified error code, message, and inner exception.
Declaration
public CryptoException(CryptoErrorCode errorCode, string message, Exception innerException)
Parameters
| Type | Name | Description |
|---|---|---|
| CryptoErrorCode | errorCode | The error code indicating the type of failure. |
| string | message | The error message that explains the reason for the exception. |
| Exception | innerException | The exception that is the cause of the current exception. |
Properties
ErrorCode
Gets the structured error code that identifies the specific type of cryptographic failure that caused this exception. Use this value for programmatic error handling rather than parsing Message.
Declaration
public CryptoErrorCode ErrorCode { get; }
Property Value
| Type | Description |
|---|---|
| CryptoErrorCode | A CryptoErrorCode value indicating the failure category. Unknown is used when no more specific code applies. |