-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
294 additions
and
87 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,6 @@ | ||
*Version 1.1.0* | ||
|
||
- The `Encryptor` type is now a trait which is implemented by the | ||
`AesHmacEncryptor` and `AesGcmEncryptor` types. | ||
- The `set_cipher` function has been renamed to `set_cipher_key_size` | ||
and the `EncryptorCipher` type has been renamed to `KeySize`. |
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
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
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,12 @@ | ||
require 'active_support' | ||
require 'json' | ||
|
||
cipher = 'aes-256-gcm' | ||
|
||
key_base = 'helloworld' | ||
key_gen = ActiveSupport::KeyGenerator.new(key_base, iterations: 1000) | ||
|
||
salt = key_gen.generate_key('test salt')[0, ActiveSupport::MessageEncryptor.key_len(cipher)] | ||
encryptor = ActiveSupport::MessageEncryptor.new(salt, cipher: cipher, serializer: JSON) | ||
|
||
puts "Decrypted message: #{encryptor.decrypt_and_verify(STDIN.read.chomp)}" |
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,31 @@ | ||
|
||
extern crate message_verifier; | ||
|
||
use message_verifier::{Encryptor, AesGcmEncryptor, DerivedKeyParams}; | ||
|
||
use std::io; | ||
use std::io::Read; | ||
use std::str; | ||
|
||
fn main() { | ||
let key_base = "helloworld"; | ||
let salt = "test salt"; | ||
|
||
let dkp = DerivedKeyParams::default(); | ||
let encryptor = AesGcmEncryptor::new(key_base, salt, dkp).unwrap(); | ||
|
||
let mut message = String::new(); | ||
|
||
match io::stdin().read_to_string(&mut message) { | ||
Err(_) => panic!("Read failed"), | ||
Ok(_) => { | ||
match encryptor.decrypt_and_verify(&message.trim()) { | ||
Ok(ref decrypted_result) => { | ||
println!("Decrypted Message: {}", str::from_utf8(&decrypted_result).expect("Encryptor failed")); | ||
} | ||
|
||
Err(e) => panic!("Encryptor Error: {:?}", e) | ||
} | ||
} | ||
} | ||
} |
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,14 @@ | ||
require 'active_support' | ||
require 'json' | ||
|
||
cipher = 'aes-256-gcm' | ||
|
||
key_base = 'helloworld' | ||
key_gen = ActiveSupport::KeyGenerator.new(key_base, iterations: 1000) | ||
|
||
salt = key_gen.generate_key('test salt')[0, ActiveSupport::MessageEncryptor.key_len(cipher)] | ||
encryptor = ActiveSupport::MessageEncryptor.new(salt, cipher: cipher, serializer: JSON) | ||
|
||
message = { key: 'value' } | ||
|
||
puts encryptor.encrypt_and_sign(message) |
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,15 @@ | ||
extern crate message_verifier; | ||
|
||
use message_verifier::{Encryptor, AesGcmEncryptor, DerivedKeyParams}; | ||
|
||
fn main() { | ||
let key_base = "helloworld"; | ||
let salt = "test salt"; | ||
|
||
let dkp = DerivedKeyParams::default(); | ||
let encryptor = AesGcmEncryptor::new(key_base, salt, dkp).unwrap(); | ||
|
||
let message = "{\"key\":\"value\"}"; | ||
|
||
println!("{}", encryptor.encrypt_and_sign(message).expect("Encryptor failed")); | ||
} |
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
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
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
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
Oops, something went wrong.