#密钥对 #公钥 #加密 #随机数 #密文 #密钥 #eip-1024

已撤回 eip1024-rs

EIP-1024 Rust 实现

0.1.0 2019年11月23日

#5#密文

Download history 9/week @ 2024-03-28 9/week @ 2024-04-04 55/week @ 2024-06-20 3/week @ 2024-06-27

每月 58 次下载

自定义许可证

9KB
96

EIP-1024 Crates.io 发布API文档

示例

use eip_1024;
use saltbabe::{KeyPair,Public, Secret, Error};
use saltbabe::traits::FromUnsafeSlice;

fn main() {
	let bob_sk = "mJxmrVq8pfeR80HMZBTkjV+RiND1lqPqLuCdDUiduis=";
    let bob_sk_slice: [u8; 32] = eip_1024::to_byte32(bob_sk.as_bytes());
    let alice_sk = "Rz2i6pXUKcpWt6/b+mYtPPH+PiwhyLswOjcP8ZM0dyI=";
    let alice_sk_slice: [u8; 32] = eip_1024::to_byte32(alice_sk.as_bytes());
    let alice = saltbabe::crypto_box::gen_keypair_from_secret(&bob_sk_slice);
    let bob = saltbabe::crypto_box::gen_keypair_from_secret(&alice_sk_slice);
    // Alice requests Bob's public encryption key so bob sends his encryption public key
    let bob_encrypt_keypair = eip_1024::get_encryption_keypair(*bob.secret());

    // Alice generates a random ephemeralKeyPair 
    let alice_ephemeral_keypair = saltbabe::crypto_box::gen_keypair_from_secret(alice.secret());

        
    // Encrypt data first
    let encrypted_data = eip_1024::encrypt(b"Hello world", None, **bob_encrypt_keypair.public(), *alice_ephemeral_keypair.secret()).unwrap();
        

    // Bob generates his encryptionPrivateKey
    let bob_encrypt_secret = bob_encrypt_keypair.secret(); 


    // Bob passes his encryptionPrivateKey
    // along with the encrypted blob 
    // to nacl.box.open(ciphertext, nonce, ephemPublicKey, myEncryptionPrivatekey)
    let decrypted = eip_1024::decrypt(encrypted_data, *bob_encrypt_secret).unwrap();
    
    // Decrypted message
    println!("{:?}", decrypted);
	assert_eq!(
		decrypted,
		"Hello world"
	);
}

许可证

此软件包是在GNU通用公共许可证版本3.0的条款下分发的。

有关详细信息,请参阅LICENSE

依赖项

~4MB
~52K SLoC