pub struct EncryptoRSA { /* private fields */ }Expand description
This struct is used to store your generated PrivateKey and PublicKeys, click for demo code
§Uses
use encrypto_rust::EncryptoRSA;
fn main() {
let encrypto = EncryptoRSA::init(1024);
let public_key = encrypto.get_public_key(); //returns PublicKey struct
let msg = "Alo".to_string(); // sample message to be encrypted
let enc = e.encrypt_from_string(msg.clone(), public_key.clone()); // returns encrypted msg as base64 string
let dec = encrypto.decrypt_as_string(enc); // returns decoded msg as string
let public_key_string = encrypto.sterilize_pub_key(); // IMPORTANT - returns base64 encoded public key which is to be sent to other client for encryption
let enc_from_bytes = EncryptoRSA::encrypt_from_bytes(bytes, public_key); // returns encrypted bytes as base64 string
let dec_from_bytes = encrypto.decrypt_as_bytes(enc_from_bytes); // returns bytes as Vec<u8>
assert_eq!(msg, dec);
}Implementations§
Source§impl EncryptoRSA
impl EncryptoRSA
pub fn get_public_key(&self) -> PublicKey
pub fn desterilize_pub_key(encoded: String) -> PublicKey
pub fn sterilize_pub_key(&self) -> String
pub fn encrypt_from_string(&self, val: String, pub_key: PublicKey) -> String
pub fn encrypt_from_bytes(&self, bytes: &[u8], pub_key: PublicKey) -> String
pub fn decrypt_as_string(&self, val: String) -> String
pub fn decrypt_as_bytes(&self, val: String) -> Vec<u8> ⓘ
Trait Implementations§
Source§impl Clone for EncryptoRSA
impl Clone for EncryptoRSA
Source§fn clone(&self) -> EncryptoRSA
fn clone(&self) -> EncryptoRSA
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for EncryptoRSA
impl Debug for EncryptoRSA
Source§impl Default for EncryptoRSA
impl Default for EncryptoRSA
Source§fn default() -> EncryptoRSA
fn default() -> EncryptoRSA
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for EncryptoRSA
impl RefUnwindSafe for EncryptoRSA
impl Send for EncryptoRSA
impl Sync for EncryptoRSA
impl Unpin for EncryptoRSA
impl UnwindSafe for EncryptoRSA
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more