QuickCrypto class

QuickCrypto provides a set of utility methods for cryptographic operations.

This class contains static methods for generating random bytes, hashing data, and performing other cryptographic operations commonly used in various applications.

Constructors

QuickCrypto()

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Properties

isSealed → bool
Whether seal was called on the RNG. Also returns true once blockchainUtils itself is sealed, so sealing the backend also locks the random source.
no setter
prng → Rng
no setter

Static Methods

aes<T extends Object?>(List<int> key, T use(BuBlockCipher cipher)) → T
Runs use with a fresh AES block cipher built from key, then wipes it. The instance must be clean after you don't need it; this method guarantees that, even if use throws.
aesCtr<T extends Object?>(List<int> key, List<int> counter, T use(BuAesCtr cipher)) → T
Runs use with a fresh AES-CTR cipher built from key/counter, then wipes it. The instance must be clean after you don't need it; this method guarantees that, even if use throws.
aesCtrInstance(List<int> key, List<int> counter) → BuAesCtr
aesEcb<T extends Object?>(List<int> key, T use(BuAesEcb cipher), {PaddingAlgorithm? padding = PaddingAlgorithm.pkcs7}) → T
Runs use with a fresh AES-ECB cipher, then wipes it. The instance must be clean after you don't need it; this method guarantees that, even if use throws.
aesEcbDecrypt(List<int> key, List<int> data, {PaddingAlgorithm? paddingAlgorithm}) → BuBytes
Decrypt the input data using AES(ECB)
aesEcbEncrypt(List<int> key, List<int> data, {PaddingAlgorithm? paddingAlgorithm}) → BuBytes
Encrypt the input data using AES(ECB)
aesEcbInstance(List<int> key, {PaddingAlgorithm? padding = PaddingAlgorithm.pkcs7}) → BuAesEcb
aesInstance(List<int> key) → BuBlockCipher
blake2b<T extends Object?>(T use(BuSerializableHash<BuHashState> cipher), {int digestLength = 64, Blake2Config? config}) → T
Runs use with a fresh BLAKE2b hash, then wipes it. The instance must be clean after you don't need it; this method guarantees that, even if use throws.
blake2b128Hash(List<int> data, {List<int>? key, List<int>? salt, List<int>? personalization, List<List<int>> extraBlocks = const []}) → BuBytes
Calculate the BLAKE2b-128 hash of the input data
blake2b160Hash(List<int> data, {List<int>? key, List<int>? salt, List<int>? personalization, List<List<int>> extraBlocks = const []}) → BuBytes
Calculate the BLAKE2b-160 hash of the input data
blake2b224Hash(List<int> data, {List<int>? key, List<int>? salt, List<int>? personalization, List<List<int>> extraBlocks = const []}) → BuBytes
Calculate the BLAKE2b-224 hash of the input data
blake2b256Hash(List<int> data, {List<int>? key, List<int>? salt, List<int>? personalization, List<List<int>> extraBlocks = const []}) → BuBytes
Calculate the BLAKE2b-256 hash of the input data
blake2b32Hash(List<int> data, {List<int>? key, List<int>? salt, List<int>? personalization, List<List<int>> extraBlocks = const []}) → BuBytes
Calculate the BLAKE2b-32 hash of the input data
blake2b40Hash(List<int> data, {List<int>? key, List<int>? salt, List<int>? personalization, List<List<int>> extraBlocks = const []}) → BuBytes
Calculate the BLAKE2b-40 hash of the input data
blake2b512Hash(List<int> data, {List<int>? key, List<int>? salt, List<int>? personalization, List<List<int>> extraBlocks = const []}) → BuBytes
Calculate the BLAKE2b-512 hash of the input data
blake2b64Hash(List<int> data, {List<int>? key, List<int>? salt, List<int>? personalization, List<List<int>> extraBlocks = const []}) → BuBytes
Calculate the BLAKE2b-64 hash of the input data
blake2bHash(List<int>? data, int digestSize, {List<int>? key, List<int>? salt, List<int>? personalization, List<List<int>> batch = const []}) → BuBytes
blake2bInstance({int digestLength = 64, Blake2Config? config}) → BuSerializableHash<BuHashState>
blake2s<T extends Object?>(T use(BuSerializableHash<BuHashState> cipher), {int digestLength = 32, Blake2Config? config}) → T
Runs use with a fresh BLAKE2s hash, then wipes it. The instance must be clean after you don't need it; this method guarantees that, even if use throws.
blake2s256Hash(List<int> data, {List<int>? key, List<int>? salt, List<int>? personalization, List<List<int>> extraBlocks = const []}) → BuBytes
Calculate the BLAKE2s-256 hash of the input data
blake2sInstance({int digestLength = 32, Blake2Config? config}) → BuSerializableHash<BuHashState>
chacha20<T extends Object?>(List<int> key, T use(BuStreamCipher cipher)) → T
Runs use with a fresh ChaCha20 stream cipher built from key, then wipes it. The instance must be clean after you don't need it; this method guarantees that, even if use throws.
chacha20Instance(List<int> key) → BuStreamCipher
chacha20Poly1305<T extends Object?>(List<int> key, T use(BuAead cipher)) → T
Runs use with a fresh ChaCha20-Poly1305 AEAD built from key, then wipes it. The instance must be clean after you don't need it; this method guarantees that, even if use throws.
chaCha20Poly1305Decrypt({required List<int> key, required List<int> nonce, required List<int> cipherText, List<int>? assocData}) → BuBytes
Decrypt data using the ChaCha20-Poly1305 authenticated encryption algorithm. Requires a key, nonce, ciphertext, and optional associated data.
chaCha20Poly1305Encrypt({required List<int> key, required List<int> nonce, required List<int> plainText, List<int>? assocData}) → BuBytes
Encrypt data using the ChaCha20-Poly1305 authenticated encryption algorithm. Requires a key, nonce, plaintext, and optional associated data.
chacha20Poly1305Instance(List<int> key) → BuAead
generateRandom({int length = 32}) → BuBytes
This function generates a random List<int> of the specified size (default is 32 bytes).
generateRandomFromRng({int length = 32, Rng? rng}) → BuBytes
This function generates a random List<int> of the specified size (default is 32 bytes).
generateRandomHex([int size = 32]) → String
generateRandomInt(int max) → int
generateRandomString(int length, {String charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'}) → String
generateRandoomBool() → bool
generateUniqueRandom({int length = 32, List<List<int>> existingKeys = const []}) → BuBytes
generateUniqueRandomHex({int length = 32, List<List<int>> existingKeys = const []}) → String
generateX25519XKeyPair({List<int>? seed}) → X25519Keypair
hash160(List<int> data) → BuBytes
Calculate the RIPEMD-160 hash of the SHA-256 hash of the input data
hkdfDeriveSha256({required List<int> ikm, int length = 32, List<int>? salt, List<int>? info}) → BuBytes
Strict RFC 5869 HKDF-SHA-256 quick call, routed through the active backend (pure-Dart or native Rust). Always Extract-then-Expand; omitted salt defaults to 32 zeros (§2.2) on every backend. Prefer this over hdfkDerive for interoperable derivations.
hkdfDeriveSha512({required List<int> ikm, int length = 32, List<int>? salt, List<int>? info}) → BuBytes
Strict RFC 5869 HKDF-SHA-512 quick call, routed through the active backend (pure-Dart or native Rust). Always Extract-then-Expand; omitted salt defaults to 64 zeros (§2.2) on every backend. Prefer this over hdfkDerive for interoperable derivations.
hmacSha256<T extends Object?>(List<int> key, T use(BuSerializableHash<BuHashState> cipher)) → T
Runs use with a fresh HMAC-SHA-256 built from key, then wipes it. The instance must be clean after you don't need it; this method guarantees that, even if use throws.
hmacsha256Hash(List<int> key, List<int> data) → BuBytes
Calculate the HMAC-SHA-256 hash of the input data using the provided key
hmacSha256Instance(List<int> key) → BuSerializableHash<BuHashState>
hmacSha384<T extends Object?>(List<int> key, T use(BuSerializableHash<BuHashState> cipher)) → T
Runs use with a fresh HMAC-SHA-384 built from key, then wipes it. The instance must be clean after you don't need it; this method guarantees that, even if use throws.
hmacSha384Hash(List<int> key, List<int> data) → BuBytes
Calculate the HMAC-SHA-384 hash of the input data using the provided key
hmacSha384Instance(List<int> key) → BuSerializableHash<BuHashState>
hmacSha512<T extends Object?>(List<int> key, T use(BuSerializableHash<BuHashState> cipher)) → T
Runs use with a fresh HMAC-SHA-512 built from key, then wipes it. The instance must be clean after you don't need it; this method guarantees that, even if use throws.
hmacSha512Hash(List<int> key, List<int> data) → BuBytes
Calculate the HMAC-SHA-512 hash of the input data using the provided key
hmacSha512HashHalves(List<int> key, List<int> data) → (BuBytes, BuBytes)
Calculate the HMAC-SHA-512 hash of the input data using the provided key and split the result into two halves. Return a tuple containing both halves
hmacSha512Instance(List<int> key) → BuSerializableHash<BuHashState>
keccak<T extends Object?>(T use(BuSerializableHash<BuHashState> cipher), {int digestLength = 64}) → T
Runs use with a fresh Keccak hash, then wipes it. The instance must be clean after you don't need it; this method guarantees that, even if use throws.
keccak256Hash(List<int> data) → BuBytes
Calculate the Keccak-256 hash of the input data
keccakF1600(BuBytes src) → BuBytes
keccakInstance({int digestLength = 64}) → BuSerializableHash<BuHashState>
md4<T extends Object?>(T use(BuSerializableHash<BuHashState> cipher)) → T
Runs use with a fresh MD4 hash, then wipes it. The instance must be clean after you don't need it; this method guarantees that, even if use throws.
md4Instance() → BuSerializableHash<BuHashState>
md5<T extends Object?>(T use(BuSerializableHash<BuHashState> cipher)) → T
Runs use with a fresh MD5 hash, then wipes it. The instance must be clean after you don't need it; this method guarantees that, even if use throws.
md5Hash(List<int> data) → BuBytes
md5Instance() → BuSerializableHash<BuHashState>
nextU32() → int
nextU64() → BigInt
pbkdf2Sha256DeriveKey({required List<int> password, required List<int> salt, required int iterations, int? dklen}) → BuBytes
pbkdf2Sha512DeriveKey({required List<int> password, required List<int> salt, required int iterations, int? dklen}) → BuBytes
Derive a key from a password using PBKDF2 algorithm
processCtr({required List<int> key, required List<int> iv, required List<int> data}) → BuBytes
ripemd128<T extends Object?>(T use(BuSerializableHash<BuHashState> cipher)) → T
Runs use with a fresh RIPEMD-128 hash, then wipes it. The instance must be clean after you don't need it; this method guarantees that, even if use throws.
ripemd128Instance() → BuSerializableHash<BuHashState>
ripemd160<T extends Object?>(T use(BuSerializableHash<BuHashState> cipher)) → T
Runs use with a fresh RIPEMD-160 hash, then wipes it. The instance must be clean after you don't need it; this method guarantees that, even if use throws.
ripemd160Hash(List<int> data) → BuBytes
Calculate the RIPEMD-160 hash of the input data
ripemd160Instance() → BuSerializableHash<BuHashState>
ripemd256<T extends Object?>(T use(BuSerializableHash<BuHashState> cipher)) → T
Runs use with a fresh RIPEMD-256 hash, then wipes it. The instance must be clean after you don't need it; this method guarantees that, even if use throws.
ripemd256Instance() → BuSerializableHash<BuHashState>
ripemd320<T extends Object?>(T use(BuSerializableHash<BuHashState> cipher)) → T
Runs use with a fresh RIPEMD-320 hash, then wipes it. The instance must be clean after you don't need it; this method guarantees that, even if use throws.
ripemd320Instance() → BuSerializableHash<BuHashState>
salsaBoxBeforenm({required List<int> peerPublicKey, required List<int> secretKey}) → BuBytes
NaCl crypto_box_beforenm quick call, routed through the active backend (Dart today, native automatically once the connector gains box support). Returns the 32-byte transport key.
salsaBoxDecrypt({required List<int> peerPublicKey, required List<int> secretKey, required List<int> nonce, required List<int> sealed}) → BuBytes?
NaCl crypto_box_open_easy detached decrypt quick call, routed through the active backend. Returns plaintext, or null on authentication failure.
salsaBoxEncrypt({required List<int> peerPublicKey, required List<int> secretKey, required List<int> nonce, required List<int> plainText}) → BuBytes
NaCl crypto_box_easy detached encrypt quick call, routed through the active backend. Explicit 24-byte nonce; returns TAG || CIPHERTEXT.
salsaBoxOpen({required List<int> peerPublicKey, required List<int> secretKey, required List<int> sealed}) → BuBytes?
Opens a NONCE || TAG || CIPHERTEXT blob, routed through the active backend. Returns null when truncated or unauthenticated.
salsaBoxSeal({required List<int> peerPublicKey, required List<int> secretKey, required List<int> plainText, List<int>? nonce}) → BuBytes
NaCl crypto_box seal quick call for TON Connect, routed through the active backend: X25519 + XSalsa20-Poly1305, returning NONCE || TAG || CIPHERTEXT. Generates a fresh random 24-byte nonce (web-safe Fortuna PRNG) when nonce is omitted; pass an explicit nonce for deterministic vectors/tests.
scryptDerive(List<int> password, List<int> salt, {int dkLen = 32, int r = 8, int n = 8192, int p = 1}) → BuBytes
seal() → void
One-way latch: after seal, setupPRNG, setupRandom and setupBackendRng throw. Call once during app startup to prevent any later code from swapping the random source (e.g. with a deterministic generator that makes keys predictable). Tests never seal.
setupBackendRng({bool seal = false}) → void
Routes generateRandom through the active backend RNG (blockchainUtils.api.rng, seeded below when necessary).
setupPRNG(Rng prng, {bool seal = false}) → void
setupRandom(CbGenerateRandom? random, {bool seal = false}) → void
sha1<T extends Object?>(T use(BuSerializableHash<BuHashState> cipher)) → T
Runs use with a fresh SHA-1 hash, then wipes it. The instance must be clean after you don't need it; this method guarantees that, even if use throws.
sha1Hash(List<int> data) → BuBytes
sha1Instance() → BuSerializableHash<BuHashState>
sha224Hash(List<int> data) → BuBytes
Calculate the SHA-256 hash of the input data
sha256<T extends Object?>(T use(BuSerializableHash<BuHashState> cipher)) → T
Runs use with a fresh SHA-256 hash, then wipes it. The instance must be clean after you don't need it; this method guarantees that, even if use throws.
sha256DoubleHash(List<int> data) → BuBytes
Calculate the SHA-256 hash of the SHA-256 hash of the input data
sha256Hash(List<int> data) → BuBytes
Calculate the SHA-256 hash of the input data
sha256Instance() → BuSerializableHash<BuHashState>
sha3<T extends Object?>(T use(BuSerializableHash<BuHashState> cipher), {int digestLength = 32}) → T
Runs use with a fresh SHA-3 hash, then wipes it. The instance must be clean after you don't need it; this method guarantees that, even if use throws.
sha3256Hash(List<int> data) → BuBytes
Calculate the SHA-3-256 hash of the input data
sha384Hash(List<int> data) → BuBytes
Calculate the SHA-512 hash of the input data
sha3Instance({int digestLength = 32}) → BuSerializableHash<BuHashState>
sha512<T extends Object?>(T use(BuSerializableHash<BuHashState> cipher)) → T
Runs use with a fresh SHA-512 hash, then wipes it. The instance must be clean after you don't need it; this method guarantees that, even if use throws.
sha512256<T extends Object?>(T use(BuSerializableHash<BuHashState> cipher)) → T
Runs use with a fresh SHA-512/256 hash, then wipes it. The instance must be clean after you don't need it; this method guarantees that, even if use throws.
sha512256Hash(List<int> data) → BuBytes
Calculate the SHA-512/256 hash of the input data
sha512256Instance() → BuSerializableHash<BuHashState>
sha512Hash(List<int> data) → BuBytes
Calculate the SHA-512 hash of the input data
sha512HashHalves(List<int> data) → (BuBytes, BuBytes)
Computes the SHA512 hash of the input data and returns its halves.
sha512Instance() → BuSerializableHash<BuHashState>
shake128<T extends Object?>(T use(BuSerializableHash<BuHashState> cipher)) → T
Runs use with a fresh SHAKE-128 XOF, then wipes it. The instance must be clean after you don't need it; this method guarantees that, even if use throws.
shake128Instance() → BuSerializableHash<BuHashState>
shake256<T extends Object?>(T use(BuSerializableHash<BuHashState> cipher)) → T
Runs use with a fresh SHAKE-256 XOF, then wipes it. The instance must be clean after you don't need it; this method guarantees that, even if use throws.
shake256Hash(List<int> data, int outlen) → BuBytes
shake256Instance() → BuSerializableHash<BuHashState>
tryChaCha20Poly1305Decrypt({required List<int> key, required List<int> nonce, required List<int> cipherText, List<int>? assocData}) → BuBytes?
Decrypt data using the ChaCha20-Poly1305 authenticated encryption algorithm. Requires a key, nonce, ciphertext, and optional associated data.
twoX128(List<int> data) → BuBytes
twoX256(List<int> data) → BuBytes
twoX64(List<int> data) → BuBytes
xsalsa20Poly1305<T extends Object?>(List<int> key, T use(BuAead cipher)) → T
Runs use with a fresh XSalsa20-Poly1305 AEAD built from key, then wipes it. The instance must be clean after you don't need it; this method guarantees that, even if use throws.
xsalsa20Poly1305Decrypt({required List<int> key, required List<int> nonce, required List<int> cipherText}) → BuBytes
Decrypt with XSalsa20-Poly1305. Throws CryptoException on authentication failure.
xsalsa20Poly1305Encrypt({required List<int> key, required List<int> nonce, required List<int> plainText}) → BuBytes
Encrypt with XSalsa20-Poly1305 (NaCl secretbox order: 16-byte tag || ciphertext).
xsalsa20Poly1305Instance(List<int> key) → BuAead
XSalsa20-Poly1305 (NaCl secretbox) AEAD from a 32-byte key. Strict 24-byte nonce. Pure-Dart on every backend (web-safe).
xxHash<T extends Object?>(T use(BuSerializableHash<BuHashState> cipher), {int bitLength = 64}) → T
Runs use with a fresh XXHash, then wipes it. The instance must be clean after you don't need it; this method guarantees that, even if use throws.
xxHashInstance({int bitLength = 64}) → BuSerializableHash<BuHashState>

Constants

blake2b32DigestSize → const int
Define the size of BLAKE2b-32 digests, which is 4 bytes (32 bits)
blake2b40DigestSize → const int
Define the size of BLAKE2b-40 digests, which is 5 bytes (40 bits)
blake2b64DigestSize → const int
Define the size of BLAKE2b-32 digests, which is 4 bytes (32 bits)
blake2b128DigestSize → const int
Define the size of BLAKE2b-160 digests, which is 20 bytes (128 bits)
blake2b160DigestSize → const int
Define the size of BLAKE2b-160 digests, which is 20 bytes (160 bits)
blake2b224DigestSize → const int
Define the size of BLAKE2b-224 digests, which is 28 bytes (224 bits)
blake2b256DigestSize → const int
Define the size of BLAKE2b-256 digests, which is 32 bytes (256 bits)
blake2b512DigestSize → const int
Define the size of BLAKE2b-512 digests, which is 64 bytes (512 bits)
chacha20Polu1305Keysize → const int
Define the key size for ChaCha20-Poly1305, which is 32 bytes
chacha20Polu1305Taglenght → const int
Define the tag length for ChaCha20-Poly1305, which is 16 bytes
hash160DigestSize → const int
Define the size of RIPEMD-160 digests, which is 20 bytes (160 bits)
hmacSha512DigestSize → const int
Define the size of HMAC-SHA-512 digests, which is 64 bytes (512 bits)
sha256DigestSize → const int
Static property that defines the size of SHA-256 digests in bytes
sha512DigestLength → const int
Gets the length of the SHA512 digest.
sha3256DigestSize → const int
Define the size of SHA-3-256 digests, which is 32 bytes (256 bits)
twoX64DigestSize → const int
twoX128DigestSize → const int
twoX256DigestSize → const int
xsalsa20Poly1305KeySize → const int
Define the key size for XSalsa20-Poly1305, which is 32 bytes
xsalsa20Poly1305NonceSize → const int
Define the nonce size for XSalsa20-Poly1305, which is 24 bytes
xsalsa20Poly1305TagLength → const int
Define the tag length for XSalsa20-Poly1305, which is 16 bytes