公钥 加密转换成lmk加密_为什么要同时使用三个键,为什么要使用两个键? 满足转换(代理)加密

公钥 加密转换成lmk加密

Now you should know that in public key encryption, that you can have a public key and a private key. Normally if Alice sends encrypted data to Bob, he will use his public key to encrypt the data (Bpub), and then Bob would use his private key (Bpriv) to decrypt it.

现在您应该知道,在公用密钥加密中,可以有一个公用密钥和一个专用密钥。 通常,如果Alice将加密的数据发送给Bob,则他将使用其公共密钥对数据(Bpub)进行加密,然后Bob将使用其私钥(Bpriv)对其进行解密。

But now let’s say we have two key pairs: (Apriv, Apub) and (Bpriv, Bpub), and who are owned by Alice and Bob, respectively. Could we encrypt with Alice’s public key (Apub) and then for it to be decrypted with Bob’s private key (Bpriv)? This is known as transform encryption, and where we have a special transform key (Apub -> Bpub) using Alice’s private key (Apriv) and Bob’s public key (Bpub). We then could pass the encrypted data, encrypted with Alice’s public key (Apub) to Trent, and then to also send Trent the transformation key. Trent can then create the required ciphertext for Bob, and which he can only decrypt with his private key (Bpriv).

但是,现在让我们说我们有两个密钥对:(Apriv,Apub)和(Bpriv,Bpub),分别由Alice和Bob拥有。 我们可以用爱丽丝的公钥(Apub)加密,然后用鲍勃的私钥(Bpriv)解密吗? 这就是所谓的转换加密 ,在这里我们有一个特殊的转换密钥 (Apub-> Bpub),使用Alice的私钥(Apriv)和Bob的公钥(Bpub)。 然后,我们可以将加密数据(使用Alice的公共密钥(Apub)加密)传递给Trent,然后再将转换密钥发送给Trent。 然后,Trent可以为Bob创建所需的密文,并且只能使用其私钥(Bpriv)对其进行解密。

Now, let’s say that Alice wants to send a secret message to a group (Bob, Carol and Dave), and where the group has its own public key, and where each of the group has the required private key for the group. Now Alice can use Trent as a trusted proxy:

现在,假设爱丽丝想向某个组(鲍勃,卡罗尔和戴夫)发送秘密消息,并且该组具有自己的公钥,并且每个组都具有该组所需的私钥。 现在,爱丽丝可以使用Trent作为受信任的代理:

  1. Alice uses her public key (Apub) and encrypts the data, and sends it to Trent to store.

    爱丽丝使用她的公共密钥(Apub)对数据进行加密,然后将其发送到Trent进行存储。
  2. Alice then generates a transform key for the group, and desposits this with Trent.

    然后,爱丽丝为该组生成一个转换密钥,并将其存储到Trent中。
  3. Bob then asks Trent for the encrypted data, and Trent uses the transform to convert it into a ciphertext.

    然后,Bob向Trent询问加密数据,然后Trent使用转换将其转换为密文。
  4. Bob then takes the ciphertext from Trent, and then decrypts with the group’s private key.

    然后,Bob从Trent中获取密文,然后使用该组的私钥解密。

In this way Trent is the proxy for the encrypted data, but Trent cannot read the secret message that Alice is sending, and Alice cannot see who is requesting the enrypted data. We thus preserve the privacy of the request from Bob, but where Trent cannot read the message.

这样,Trent是加密数据的代理,但是Trent无法读取Alice正在发送的秘密消息,并且Alice无法看到谁在请求加密数据。 因此,我们保留了Bob的请求的私密性,但Trent无法读取消息。

源代码 (Source code)

So let’s implement using Rust. First we create the Rust project with:

因此,让我们使用Rust实现。 首先,我们使用以下命令创建Rust项目:

cargo new transform

We then go into the transform folder, and add the following to the cargo.toml file:

然后,我们进入转换文件夹,并将以下内容添加到cargo.toml文件中:

[package]
name = "transform"
version = "0.1.0"
authors = ["billbuchanan "]
edition = "2018"[dependencies]
recrypt = "0.11.0"
hex = "0.4.2"
pad = "0.1"

Next we go into the src folder, and edit the main.rs file with:

接下来,我们进入src文件夹,并使用以下命令编辑main.rs文件:

use recrypt::prelude::*;
use recrypt::api::Plaintext;
use pad::PadStr;
use std::env;
fn main() {
fn unsize
(x: &[T]) -> &[T] { x }
// create a new recrypt
let recrypt = Recrypt::new();
let mut mystr="Hello";
let args: Vec<String> = env::args().collect();
if args.len() >1 { mystr = &args[1];}
let x=Plaintext::new_from_slice(mystr.pad_to_width_with_char(384,' ').as_bytes());
let pt = x.unwrap();
let signing_keypair= recrypt.generate_ed25519_key_pair();
let (initial_priv_key, initial_pub_key) = recrypt.generate_key_pair().unwrap();
let encrypted_val = recrypt.encrypt(&pt, &initial_pub_key, &signing_keypair).unwrap();
let (target_priv_key, target_pub_key) = recrypt.generate_key_pair().unwrap();
let initial_to_target_transform_key = recrypt.generate_transform_key(
&initial_priv_key,
&target_pub_key,
&signing_keypair).unwrap();
let transformed_val = recrypt.transform(
encrypted_val,
initial_to_target_transform_key,
&signing_keypair).unwrap();
let decrypted_val = recrypt.decrypt(transformed_val, &target_priv_key).unwrap();
println!("\nInput string:\t{} ",mystr);
println!("\nSigning key:\t{} ",hex::encode(unsize(signing_keypair.bytes())));
println!("\nInitial Private key:\t{} ",hex::encode(unsize(initial_priv_key.bytes())));
let (x,y)=initial_pub_key.bytes_x_y();
println!("\nInitial Public key:\t{},{} ",hex::encode(unsize(x)),hex::encode(unsize(y)) );
println!("\nTarget Private key:\t{} ",hex::encode(unsize(target_priv_key.bytes())));
let (x,y)=target_pub_key.bytes_x_y();
println!("\nTarget Public key:\t{},{} ",hex::encode(unsize(x)),hex::encode(unsize(y)) );
println!("\nDecrypted:\t{} ",String::from_utf8_lossy(decrypted_val.bytes()));
}

You can run it here:

您可以在这里运行它:

https://asecuritysite.com/encryption/rust_transform

https://asecuritysite.com/encryption/rust_transform

翻译自: https://medium.com/asecuritysite-when-bob-met-alice/why-use-two-keys-when-you-can-have-three-meet-transform-proxy-encryption-1ae3bdbc2aaa

公钥 加密转换成lmk加密

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值