-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from rakurame96/example-tests
#7 Add examples using cas-lib
- Loading branch information
Showing
2 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use std::{fs::{File}, io::Write, path::Path}; | ||
|
||
use cas_lib::symmetric::{aes::CASAES256, cas_symmetric_encryption::CASAESEncryption}; | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
#[test] | ||
fn test_aes_256() { | ||
let path = Path::new("tests/test.docx"); | ||
let file_bytes: Vec<u8> = std::fs::read(path).unwrap(); | ||
let aes_nonce = <CASAES256 as CASAESEncryption>::generate_nonce(); | ||
let aes_key = <CASAES256 as CASAESEncryption>::generate_key(); | ||
let encrypted_bytes = <CASAES256 as CASAESEncryption>::encrypt_plaintext(aes_key.clone(), aes_nonce.clone(), file_bytes); | ||
let mut file = File::create("encrypted.docx").unwrap(); | ||
file.write_all(&encrypted_bytes); | ||
|
||
let path = Path::new("encrypted.docx"); | ||
let file_bytes: Vec<u8> = std::fs::read(path).unwrap(); | ||
let decrypted_bytes = <CASAES256 as CASAESEncryption>::decrypt_ciphertext(aes_key, aes_nonce, file_bytes); | ||
let mut file = File::create("decrypted.docx").unwrap(); | ||
file.write_all(&decrypted_bytes); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
This is a sample document. | ||
It contains several lines of text. | ||
We will use this document to demonstrate signing and verifying using RSA encryption. |