临时Diffie-Hellman Java密钥交换

时间:2019-09-24 18:21:58

标签: java diffie-hellman

这是我关于stackoverflow的第一篇文章。我总是找到我需要的东西,但是今天我不得不提一个问题。

我正在编写一个要连接到服务器的程序。服务器使用Diffie-Hellman算法对数据进行加密。

这里是服务器代码[C ++]

///// SEND KEY
Integer p("0xB10B8F96A080E01DDE92DE5EAE5D54EC52C99FBCFB06A3C6"
"9A6A9DCA52D23B616073E28675A23D189838EF1E2EE652C0"
"13ECB4AEA906112324975C3CD49B83BFACCBDD7D90C4BD70"
"98488E9C219A73724EFFD6FAE5644738FAA31A4FF55BCCC0"
"A151AF5F0DC8B4BD45BF37DF365C1A65E68CFDA76D4DA708"
"DF1FB2BC2E4A4371");

Integer g("0xA4D1CBD5C3FD34126765A442EFB99905F8104DD258AC507F"
"D6406CFF14266D31266FEA1E5C41564B777E690F5504F213"
"160217B4B01B886A5E91547F9E2749F4D7FBD7D3B9A92EE1"
"909D0D2263F80A76A6A24C087A091F531DBF0A0169B6A28A"
"D662A4D18E73AFA32D779D5918D08BC8858F4DCEF97C2A24"
"855E6EEB22B3B2E5");

Integer q("0xF518AA8781A8DF278ABA4E7D64B7CB9D49462353");

AutoSeededRandomPool asrp;

dh_.AccessGroupParameters().Initialize(p, q, g);

p = dh_.GetGroupParameters().GetModulus();
q = dh_.GetGroupParameters().GetSubgroupOrder();
g = dh_.GetGroupParameters().GetGenerator();

Integer v = ModularExponentiation(g, q, p);

SecByteBlock spubkey(dh2_.StaticPublicKeyLength());
SecByteBlock epubkey(dh2_.EphemeralPublicKeyLength());

sprivkey.New(dh2_.StaticPrivateKeyLength());
eprivkey.New(dh2_.EphemeralPrivateKeyLength());

dh2_.GenerateStaticKeyPair(asrp, sprivkey, spubkey);
dh2_.GenerateEphemeralKeyPair(asrp, eprivkey, epubkey);

send(spubkey, epubkey);


///////// KEY AGREE
//buf = recived keys [spubkey+epubkey]
const size_t spub_key_length = dh2_.StaticPublicKeyLength();
shared_.New(dh2_.AgreedValueLength());
dh2_.Agree(shared_, sprivkey, eprivkey, buf, buf + spub_key_length)

我现在想与JAVA中的程序交换密钥。

我不太了解该怎么做。而且,JAVA中的所有示例都不包含参数q和临时键。

Stackoverflow。希望你能帮助我! 我坐在上面好几天...

谢谢

0 个答案:

没有答案