Added types for crypto

This commit is contained in:
dominicbachmann 2022-04-06 21:10:37 +02:00
parent 8212868b92
commit de37ee9f1c
2 changed files with 6 additions and 4 deletions

View File

@ -1,3 +1,5 @@
// TODO: Make this functions generic
async function send({
method,
path,

View File

@ -1,13 +1,13 @@
import crypto from 'crypto';
const algorithm = 'aes-256-ctr';
export const base64Encode = (text: string) => {
export const base64Encode = (text: string): string => {
return Buffer.from(text).toString('base64');
};
export const base64Decode = (text: string) => {
export const base64Decode = (text: string): string => {
return Buffer.from(text, 'base64').toString('ascii');
};
export const encrypt = (text: string) => {
export const encrypt = (text: string): string => {
if (text) {
const iv = crypto.randomBytes(16);
const cipher = crypto.createCipheriv(algorithm, process.env['COOLIFY_SECRET_KEY'], iv);
@ -19,7 +19,7 @@ export const encrypt = (text: string) => {
}
};
export const decrypt = (hashString: string) => {
export const decrypt = (hashString: string): string => {
if (hashString) {
const hash: Hash = JSON.parse(hashString);
const decipher = crypto.createDecipheriv(