Task: Add random bytes and string for default crypto

This commit is contained in:
Sambo Chea 2022-02-14 16:52:39 +07:00
parent 3c12c69606
commit fb694eb5a2
Signed by: sombochea
GPG Key ID: 3C7CF22A05D95490

View File

@ -46,4 +46,12 @@ const decrypt = (
return decrypted
}
export { encrypt, decrypt }
const cryptoRandomBytes = (length: number): Buffer => {
return Buffer.from(crypto.randomBytes(length))
}
const cryptoRandomString = (length: number): string => {
return cryptoRandomBytes(length).toString(DEFAULT_BUFFER_TYPE)
}
export { encrypt, decrypt, cryptoRandomBytes, cryptoRandomString }