Compare commits

..

No commits in common. "e943e4cbb565da5aa842b71565a0d9537ee441e3" and "9e5c4126a56b40a06ece7b734c33912cb44df85b" have entirely different histories.

View File

@ -1,12 +1,12 @@
use crypto_box::{
aead::{Aead, AeadCore, OsRng},
PublicKey, SalsaBox, SecretKey,
};
use std::io::Write; use std::io::Write;
use std::net::TcpStream; use std::net::TcpStream;
use crypto_box::{
aead::{Aead, AeadCore, OsRng},
SalsaBox, PublicKey, SecretKey
};
fn main() { fn main() {
let port: u32 = 7878; // Port Server let port: u32 = 7878;
//let stream = TcpStream::connect("172.30.16.1:8080"); //let stream = TcpStream::connect("172.30.16.1:8080");
//let stream = TcpStream::connect("27.0.0.1:8080"); //let stream = TcpStream::connect("27.0.0.1:8080");
match TcpStream::connect(format!("localhost:{}", port)) { match TcpStream::connect(format!("localhost:{}", port)) {
@ -14,9 +14,10 @@ fn main() {
println!("Successfully connected to server"); println!("Successfully connected to server");
let bob_init_pub_key = PublicKey::from([ let bob_init_pub_key = PublicKey::from([
0xe8, 0x98, 0xc, 0x86, 0xe0, 0x32, 0xf1, 0xeb, 0x29, 0x75, 0x5, 0x2e, 0x8d, 0x65, 0xe8, 0x98, 0xc, 0x86, 0xe0, 0x32, 0xf1, 0xeb,
0xbd, 0xdd, 0x15, 0xc3, 0xb5, 0x96, 0x41, 0x17, 0x4e, 0xc9, 0x67, 0x8a, 0x53, 0x78, 0x29, 0x75, 0x5, 0x2e, 0x8d, 0x65, 0xbd, 0xdd,
0x9d, 0x92, 0xc7, 0x54, 0x15, 0xc3, 0xb5, 0x96, 0x41, 0x17, 0x4e, 0xc9,
0x67, 0x8a, 0x53, 0x78, 0x9d, 0x92, 0xc7, 0x54,
]); ]);
// Generate a random secret key. // Generate a random secret key.
@ -58,16 +59,11 @@ fn main() {
// //
// Decrypt the message, using the same randomly generated nonce // Decrypt the message, using the same randomly generated nonce
let decrypted_plaintext = let decrypted_plaintext = salsa_box.decrypt(&nonce, &ciphertext[..]).expect("Fehler");
salsa_box.decrypt(&nonce, &ciphertext[..]).expect("Fehler"); let dec_plain_plaintext = std::str::from_utf8(&*decrypted_plaintext).expect("");
let dec_plain_plaintext =
std::str::from_utf8(&*decrypted_plaintext).expect("");
assert_eq!(&plaintext[..], &decrypted_plaintext[..]); assert_eq!(&plaintext[..], &decrypted_plaintext[..]);
println!( println!("Sent {0:?} as cypher: {1:?}, decrypted: {2:?}, {3}", plaintext, ciphertext, decrypted_plaintext, dec_plain_plaintext);
"Sent {0:?} as cypher: {1:?}, decrypted: {2:?}, {3}",
plaintext, ciphertext, decrypted_plaintext, dec_plain_plaintext
);
} }
Err(error) => { Err(error) => {
println!("error: {error}"); println!("error: {error}");
@ -82,17 +78,3 @@ fn main() {
} }
println!("Terminated."); println!("Terminated.");
} }
fn generate_box(partner_public_key: PublicKey) -> (SalsaBox, PublicKey) {
// Generate a random secret key.
// NOTE: The secret key bytes can be accessed by calling `secret_key.as_bytes()`
let own_secret_key = SecretKey::generate(&mut OsRng);
// Get the public key for the secret key we just generated
let own_public_key = own_secret_key.public_key().clone();
// Create a `SalsaBox` by performing Diffie-Hellman key agreement between
// the two keys.
let salsa_box = SalsaBox::new(&partner_public_key, &own_secret_key);
(salsa_box, own_public_key)
}