envio 0.1.0

Envio is a command-line tool that simplifies the management of environment variables across multiple profiles. It allows users to easily switch between different configurations and apply them to their current environment. Envio also encrypts sensitive environment variable values to ensure secure storage and transmission
use colored::Colorize;
use magic_crypt::{new_magic_crypt, MagicCryptTrait};
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};

pub fn encrypt(key: String, data: String) -> Vec<u8> {
    let mc = new_magic_crypt!(key, 256);

    mc.encrypt_str_to_bytes(data)
}

pub fn decrypt(key: String, encrypted_data: &[u8]) -> String {
    let mc = new_magic_crypt!(key, 256);

    match mc.decrypt_bytes_to_bytes(encrypted_data) {
        Ok(bytes) => String::from_utf8(bytes).unwrap(),
        Err(e) => {
            println!("{}: {}", "Error".red(), e);
            std::process::exit(1);
        }
    }
}

pub fn hash_string(input: &str) -> String {
    let mut hasher = DefaultHasher::new();
    input.hash(&mut hasher);
    format!("{:x}", hasher.finish())
}