Java中的Diffie

编程入门 行业动态 更新时间:2024-10-26 08:32:47
本文介绍了Java中的Diffie-Hellman密钥交换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在开发一个Java项目,涉及通过不安全的渠道发送敏感数据。我需要知道如何使用其库在Java中实现Diffie Hellman密钥交换(DHKE)。我知道关于它的所有加密理论所以不需要详细说明,我只需要一个非常基本的实现,所以我可以让2个程序共享一个密钥。我从java2s获得了示例,但它没有完成:

I am working on a personal project in Java which involves sending sensitive data over an insecure channel. I need to know how to implement Diffie Hellman Key Exchange (DHKE) in java using its libraries. I know all the cryptographic theory about it so no need to go into details, I just need a very basic implementation so I cand have 2 programs share a secret key. I got the example from java2s, but it is not complete:

import java.math.BigInteger; import java.security.KeyFactory; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.SecureRandom; import javax.crypto.spec.DHParameterSpec; import javax.crypto.spec.DHPublicKeySpec; public class Main { public final static int pValue = 47; public final static int gValue = 71; public final static int XaValue = 9; public final static int XbValue = 14; public static void main(String[] args) throws Exception { BigInteger p = new BigInteger(Integer.toString(pValue)); BigInteger g = new BigInteger(Integer.toString(gValue)); BigInteger Xa = new BigInteger(Integer.toString(XaValue)); BigInteger Xb = new BigInteger(Integer.toString(XbValue)); int bitLength = 512; // 512 bits SecureRandom rnd = new SecureRandom(); p = BigInteger.probablePrime(bitLength, rnd); g = BigInteger.probablePrime(bitLength, rnd); createSpecificKey(p, g); } public static void createSpecificKey(BigInteger p, BigInteger g) throws Exception { KeyPairGenerator kpg = KeyPairGenerator.getInstance("DiffieHellman"); DHParameterSpec param = new DHParameterSpec(p, g); kpg.initialize(param); KeyPair kp = kpg.generateKeyPair(); KeyFactory kfactory = KeyFactory.getInstance("DiffieHellman"); DHPublicKeySpec kspec = (DHPublicKeySpec) kfactory.getKeySpec(kp.getPublic(), DHPublicKeySpec.class); } }

我如何继续?任何人都可以帮我完成剩余的代码吗?

How do I go on from this? Could anyone help me complete the remaining code?

推荐答案

正式的Oracle Docs ?他们在那里显示代码中的DH密钥交换。

What about the official Oracle Docs? They show a DH key exchange in code there.

更多推荐

Java中的Diffie

本文发布于:2023-11-16 23:15:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1607899.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Java   Diffie

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!