Used a more updated Base64 Encode and Decode method

This commit is contained in:
Maddox Werts 2024-06-14 14:12:45 -04:00
parent af2b33f197
commit 69cfd0c91f

View file

@ -1,5 +1,6 @@
// Libraries // Libraries
use ring::rand::{SecureRandom, SystemRandom}; use ring::rand::{SecureRandom, SystemRandom};
use base64::prelude::*;
// Constants // Constants
@ -23,11 +24,11 @@ impl Secure {
ciphertext[i] = value_bytes[i] ^ key_bytes[i % key_bytes.len()]; ciphertext[i] = value_bytes[i] ^ key_bytes[i % key_bytes.len()];
} }
return base64::encode(ciphertext); return BASE64_STANDARD.encode(ciphertext);
} }
// Takes in cyphertext and a key to decrypt it // Takes in cyphertext and a key to decrypt it
pub fn decrypt(cyphertext: String, key: String) -> String { pub fn decrypt(cyphertext: String, key: String) -> String {
let cyphertext_bytes = base64::decode(cyphertext).expect("(0) Decryption Failed"); let cyphertext_bytes = BASE64_STANDARD.decode(cyphertext).expect("(0) Decryption Failed");
let key_bytes = key.as_bytes(); let key_bytes = key.as_bytes();
let mut plaintext = vec![0u8; cyphertext_bytes.len()]; let mut plaintext = vec![0u8; cyphertext_bytes.len()];