Cryptography
Cryptography is the science of protecting information by transforming it into a secure format. It ensures that communications are kept confidential and are protected from unauthorized access.
Hash
Hashing transforms specific data into a hash value using a chosen hashing algorithm. This method is particularly useful for securely storing sensitive information, such as passwords, or for verifying data integrity.
Hashing is a one-way process, meaning that the original data cannot be reconstructed from the hash value.
quick.cryptography.hash(data: IHashDataRequest): Promise<IHashDataResponse | undefined>
IHashDataRequest { data: string, algorithm: HashAlgorithm, key: string }
data : The data to be hashed
algorithm : The hashing algorithm to use
HashAlgorithm { SHA1, SHA256, SHA384, SHA512, HMACSHA1, HMACSHA256, HMACSHA384, HMACSHA512 } key: The hashing to use. (If the algorithm is "HMAC" the key is used, otherwise it is not needed.)
IHashDataResponse { hashedData: string }
Here you can see an example:
async function createHash() {
let plaintext = 'This text will be encoded UTF8 and may contain special characters like § and €.';
let hashRequest: IHashDataRequest = {
algorithm: HashAlgorithm.SHA512,
data: plaintext,
key: "secretKey"
}
let hashResponse = await quick.cryptography.hash(hashRequest);
}
createHash();
Encrypt
Encrypts a specific data using the specified encryption algorithm. This process ensures that the data is safely stored or transmitted. The data is encrypted using an encryption key and can only be decrypted with the correct key.
quick.cryptography.encrypt(data: IEncryptDataRequest): Promise<IEncryptDataResponse | undefined>
IEncryptDataRequest { data: string, key: string, algorithm: EncryptionAlgorithm, ivKey?: string }
data : The data to be encrypted
key : The encryption key. (Public key must be used for RSA Algorithm.)
algorithm : Specifies which encryption algorithm to use. AES is used for encrypting large data blocks, while RSA is used for smaller data blocks (such as key encryption or digital signatures).
EncryptionAlgorithm { RSAOAEP, AESCTR, AESCBC, AESGCM }
ivKey(optional): It's an optional field used to provide a custom initialization vector (IV) or counter for encryption. For AES algorithms (like AESCTR, AESCBC, AESGCM), if ivKey is provided, it will be used as the IV or counter. If not provided, the system generates a random IV (AES-GCM uses 12 bytes, AES-CTR and AES-CBC use 16 bytes). For RSA (RSAOAEP), ivKey is not used, and no IV is needed. Example ivKeys you can use: aAB1jhPQ89o=f619, !QAZ2WSX#EDC4RFV.
IEncryptDataResponse { encryptedData: string, iv?: string }
encryptedData : Holds the encrypted data
iv (optional) : Represents the initialization vector used in encryption. ( If algorithm is "RSAOAEP", then iv is not used, otherwise it is required. )
Here you can see an example:
async function encryptData() {
let plaintext = 'This text will be encoded UTF8 and may contain special characters like § and €.';
let ivKey = '+OSPdSgZkYp5s6yi' (If you want to use an ivKey)
let requestEncrypt: IEncryptDataRequest = {
algorithm: EncryptionAlgorithm.AESGCM,
data: plaintext,
key: "secretKey",
ivKey: ivKey (optional)
}
let responseEncrypt = await quick.cryptography.encrypt(requestEncrypt);
}
encryptData();
Decrypt
Decryption is the process of converting encrypted data back to its original, readable form. Decryption uses the correct key to revert the encrypted data back to its original form. It also ensures that authorized users can access and understand the protected information.
quick.cryptography.decrypt(data: IDecryptDataRequest): Promise<IDecryptDataResponse | undefined>
IDecryptDataRequest { encryptedData: string, iv?: string, ivKey?: string key: string, algorithm: EncryptionAlgorithm, }
encryptedData : The encrypted data
iv (optional) : The initialization vector used during encryption. ( If algorithm is "RSAOAEP", then iv is not used, otherwise it is required. )
ivKey(optional): It's an optional field used to provide a custom initialization vector (IV) or counter for encryption. For AES algorithms (like AESCTR, AESCBC, AESGCM), if ivKey is provided, it will be used as the IV or counter. If not provided, the system generates a random IV (AES-GCM uses 12 bytes, AES-CTR and AES-CBC use 16 bytes). For RSA (RSAOAEP), ivKey is not used, and no IV is needed.
key : The encryption key (Private key must be used for RSA Algorithm.)
algorithm : Specifies which encryption algorithm to use
EncryptionAlgorithm { RSAOAEP, AESCTR, AESCBC, AESGCM }
IDecryptDataResponse { decryptedData: string }
decryptedData : Contains the original data decrypted from the encrypted data.
Here you can see an example:
async function decryptData(encryptedData, iv) {
let requestDecrypt: IDecryptDataRequest = {
algorithm: EncryptionAlgorithm.AESGCM,
encryptedData: encryptedData,
key: "secretKey",
iv: iv (or ivKey(optional))
}
let responseDecrypt = await quick.cryptography.decrypt(requestDecrypt);
}
decryptData();