YOUSEFUL / DELPHI / COMPONENTS
EAtlasCryptoError
The one exception class raised by every Atlas Crypto failure: bad arguments, failed authentication, CNG errors and cancel.
Description
Declared in Atlas.Crypto.Cng as class(Exception) and re-declared in Atlas.Crypto as the same class, so uses Atlas.Crypto is enough to catch it.
Messages fall into four groups:
- Opening failed. Every way a box, text or stream can fail to open raises
Decryption failed: wrong key or password, or the data was altered, so the wording tells an attacker nothing. The rawTAtlasAesGcm.DecryptandTAtlasRsa.DecryptsayDecryption failed: wrong key, or the data was altered. - Invalid arguments, each with its own message: a key of the wrong size, an empty password when sealing, an iteration count or chunk size out of range, malformed hexadecimal or base64 text, an RSA size outside 2048 to 8192 bits.
- CNG failures, as
<operation> failed (Windows status XXXXXXXX), for exampleImporting the ECDSA_P256 key failed (Windows status C000000D)for an unusable key blob. The status code is what Windows documentation is indexed by. - Cancel from a progress callback:
Encryption was cancelled,Decryption was cancelled,Hashing was cancelled.
File-system errors are not wrapped: they arrive as the RTL's EFOpenError, EFCreateError or EOSError.
This type has no members of its own beyond those listed in its description.
Examples
Report why a box did not open
Opens a box with a different key. Prints Decryption failed: wrong key or password, or the data was altered.
uses System.SysUtils, Atlas.Crypto, Atlas.CryptoBox;
procedure ShowWhyItFailed;
var
Box: TBytes;
begin
Box := TAtlasSecretBox.Seal(TAtlasSecretBox.NewKey, TAtlasBytes.OfString('secret'));
try
TAtlasSecretBox.Open(TAtlasSecretBox.NewKey, Box);
except
on E: EAtlasCryptoError do WriteLn(E.Message);
end;
end;
Related
TAtlasSecretBox · TAtlasStreamCrypt · TCngAlgorithm