CryptoUtils class
Helper class for cryptographic operations
Constructors
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 Methods
-
addPKCS7Padding(
Uint8List bytes, int blockSizeBytes) → Uint8List -
Adds a PKCS7 / PKCS5 padding to the given
bytes
andblockSizeBytes
-
ecPrivateKeyFromDerBytes(
Uint8List bytes, {bool pkcs8 = false, ECDomainParameters? parameters}) → ECPrivateKey -
Decode the given
bytes
into an ECPrivateKey. -
ecPrivateKeyFromPem(
String pem) → ECPrivateKey -
Decode a ECPrivateKey from the given
pem
String. -
ecPublicKeyFromDerBytes(
Uint8List bytes, {ECDomainParameters? parameters}) → ECPublicKey -
Decode the given
bytes
into an ECPublicKey. -
ecPublicKeyFromPem(
String pem) → ECPublicKey -
Decode a ECPublicKey from the given
pem
String. -
ecSign(
ECPrivateKey privateKey, Uint8List dataToSign, {String algorithmName = 'SHA-1/ECDSA'}) → ECSignature -
Signing the given
dataToSign
with the givenprivateKey
. -
ecSignatureFromBase64(
String b64) → ECSignature - Converts a base64 DER encoded string to an ECSignature. The der encoded content must follow the following structure.
-
ecSignatureFromDerBytes(
Uint8List data) → ECSignature - Converts the given DER bytes to an ECSignature. The der encoded content must follow the following structure.
-
ecSignatureToBase64(
ECSignature signature) → String -
Convert ECSignature
signature
to DER encoded base64 string. -
ecVerify(
ECPublicKey publicKey, Uint8List signedData, ECSignature signature, {String algorithm = 'SHA-1/ECDSA'}) → bool -
Verifying the given
signedData
with the givenpublicKey
and the givensignature
. Will return true if the givensignature
matches thesignedData
. -
ecVerifyBase64(
ECPublicKey publicKey, Uint8List origData, String signature, {String algorithm = 'SHA-1/ECDSA'}) → bool -
Verifying the given
signedData
with the givenpublicKey
and the givensignature
in base64. Will return true if the givensignature
matches thesignedData
. -
encodeEcPrivateKeyToPem(
ECPrivateKey ecPrivateKey) → String -
Enode the given elliptic curve
publicKey
to PEM format. -
encodeEcPublicKeyToPem(
ECPublicKey publicKey) → String -
Enode the given elliptic curve
publicKey
to PEM format. -
encodePrivateEcdsaKeyToPkcs8(
ECPrivateKey privateKey) → String - Encode a private ECDSA key to PKCS8 format
-
encodeRSAPrivateKeyToPem(
RSAPrivateKey rsaPrivateKey) → String -
Enode the given
rsaPrivateKey
to PEM format using the PKCS#8 standard. -
encodeRSAPrivateKeyToPemPkcs1(
RSAPrivateKey rsaPrivateKey) → String -
Enode the given
rsaPrivateKey
to PEM format using the PKCS#1 standard. -
encodeRSAPublicKeyToPem(
RSAPublicKey publicKey) → String -
Enode the given
publicKey
to PEM format using the PKCS#8 standard. -
encodeRSAPublicKeyToPemPkcs1(
RSAPublicKey rsaPublicKey) → String -
Enode the given
rsaPublicKey
to PEM format using the PKCS#1 standard. -
generateEcKeyPair(
{String curve = 'prime256v1'}) → AsymmetricKeyPair< PublicKey, PrivateKey> - Generates a elliptic curve AsymmetricKeyPair.
-
generateRSAKeyPair(
{int keySize = 2048}) → AsymmetricKeyPair< PublicKey, PrivateKey> -
Generates a RSA AsymmetricKeyPair with the given
keySize
. The default value for thekeySize
is 2048 bits. -
getBytesFromPEMString(
String pem, {bool checkHeader = true}) → Uint8List -
Helper function for decoding the base64 in
pem
. -
getHash(
Uint8List bytes, {String algorithmName = 'SHA-256'}) → String -
Get a hash for the given
bytes
using the givenalgorithm
-
getHashPlain(
Uint8List bytes, {String algorithmName = 'SHA-256'}) → Uint8List -
Get a hash for the given
bytes
using the givenalgorithm
-
getMd5ThumbprintFromBytes(
Uint8List bytes) → String -
Get a MD5 Thumbprint for the given
bytes
. -
getModulusFromRSAPrivateKeyPem(
String pem) → BigInt -
Returns the modulus of the given
pem
that represents an RSA private key. -
getPrivateKeyType(
String pem) → String -
Returns the private key type of the given
pem
-
getSecureRandom(
) → SecureRandom -
Generates a secure
FortunaRandom
-
getSha1ThumbprintFromBytes(
Uint8List bytes) → String -
Get a SHA1 Thumbprint for the given
bytes
. -
getSha256ThumbprintFromBytes(
Uint8List bytes) → String -
Get a SHA256 Thumbprint for the given
bytes
. -
i2osp(
BigInt number, {int? outLen, Endian endian = Endian.big}) → Uint8List - Conversion of integer to bytes according to RFC 3447 at datatracker.ietf.org/doc/html/rfc3447#page-8
-
osp2i(
Iterable< int> bytes, {Endian endian = Endian.big}) → BigInt - Conversion of bytes to integer according to RFC 3447 at datatracker.ietf.org/doc/html/rfc3447#page-8
-
removePKCS7Padding(
Uint8List padded) → Uint8List -
Revomes the PKCS7 / PKCS5 padding from the
padded
bytes -
rsaDecrypt(
String cipherMessage, RSAPrivateKey privateKey) → String -
Decrypt the given
cipherMessage
using the given RSAprivateKey
. -
rsaEncrypt(
String message, RSAPublicKey publicKey) → String -
Encrypt the given
message
using the given RSApublicKey
. -
rsaPrivateKeyExponentToBytes(
RSAPrivateKey privateKey) → Uint8List -
Converts the RSAPrivateKey.exponent from the given
privateKey
to a Uint8List. -
rsaPrivateKeyFromDERBytes(
Uint8List bytes) → RSAPrivateKey -
Decode the given
bytes
into an RSAPrivateKey. -
rsaPrivateKeyFromDERBytesPkcs1(
Uint8List bytes) → RSAPrivateKey -
Decode the given
bytes
into an RSAPrivateKey. -
rsaPrivateKeyFromPem(
String pem) → RSAPrivateKey -
Decode a RSAPrivateKey from the given
pem
String. -
rsaPrivateKeyFromPemPkcs1(
String pem) → RSAPrivateKey -
Decode a RSAPrivateKey from the given
pem
string formated in the pkcs1 standard. -
rsaPrivateKeyModulusToBytes(
RSAPrivateKey privateKey) → Uint8List -
Converts the RSAPrivateKey.modulus from the given
privateKey
to a Uint8List. -
rsaPssSign(
RSAPrivateKey privateKey, Uint8List dataToSign, Uint8List salt, {String algorithm = 'SHA-256/PSS'}) → Uint8List -
Signing the given
dataToSign
with the givenprivateKey
and the givensalt
. -
rsaPssVerify(
RSAPublicKey publicKey, Uint8List signedData, Uint8List signature, int saltLength, {String algorithm = 'SHA-256/PSS'}) → bool -
Verifying the given
signedData
with the givenpublicKey
, the givensignature
and the givensaltLength
. Will return true if the givensignature
matches thesignedData
. -
rsaPublicKeyExponentToBytes(
RSAPublicKey publicKey) → Uint8List -
Converts the RSAPublicKey.exponent from the given
publicKey
to a Uint8List. -
rsaPublicKeyFromDERBytes(
Uint8List bytes) → RSAPublicKey -
Decode the given
bytes
into an RSAPublicKey. -
rsaPublicKeyFromDERBytesPkcs1(
Uint8List bytes) → RSAPublicKey -
Decode the given
bytes
into an RSAPublicKey. -
rsaPublicKeyFromPem(
String pem) → RSAPublicKey -
Decode a RSAPublicKey from the given
pem
String. -
rsaPublicKeyFromPemPkcs1(
String pem) → RSAPublicKey -
Decode a RSAPublicKey from the given
pem
string formated in the pkcs1 standard. -
rsaPublicKeyModulusToBytes(
RSAPublicKey publicKey) → Uint8List -
Converts the RSAPublicKey.modulus from the given
publicKey
to a Uint8List. -
rsaSign(
RSAPrivateKey privateKey, Uint8List dataToSign, {String algorithmName = 'SHA-256/RSA'}) → Uint8List -
Signing the given
dataToSign
with the givenprivateKey
. -
rsaVerify(
RSAPublicKey publicKey, Uint8List signedData, Uint8List signature, {String algorithm = 'SHA-256/RSA'}) → bool -
Verifying the given
signedData
with the givenpublicKey
and the givensignature
. Will return true if the givensignature
matches thesignedData
.
Constants
- BEGIN_EC_PRIVATE_KEY → const String
- BEGIN_EC_PUBLIC_KEY → const String
- BEGIN_PRIVATE_KEY → const String
- BEGIN_PUBLIC_KEY → const String
- BEGIN_RSA_PRIVATE_KEY → const String
- BEGIN_RSA_PUBLIC_KEY → const String
- END_EC_PRIVATE_KEY → const String
- END_EC_PUBLIC_KEY → const String
- END_PRIVATE_KEY → const String
- END_PUBLIC_KEY → const String
- END_RSA_PRIVATE_KEY → const String
- END_RSA_PUBLIC_KEY → const String