- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我只有java中的服务器端代码,我想为我的服务器使用diffie-hellman加密,所以任何人都可以帮助我,我是编程新手,我刚刚开始学习,所以这是我的作业和截止日期非常接近,所以任何人都可以帮助我,那就太好了......到目前为止,我得到了这个代码,但我不知道如何将它与我的服务器代码合并
import java.util.*;
import java.math.BigInteger;
public class DiffieHellmanBigInt {
final static BigInteger one = new BigInteger("1");
public static void main(String args[]) {
Scanner stdin = new Scanner(System.in);
BigInteger p;
// Get a start spot to pick a prime from the user.
System.out.println("Enter the approximate value of p you want.");
String ans = stdin.next();
p = getNextPrime(ans);
System.out.println("Your prime is "+p+".");
// Get the base for exponentiation from the user.
System.out.println("Now, enter a number in between 2 and p-1.");
BigInteger g = new BigInteger(stdin.next());
// Get A's secret number.
System.out.println("Person A: enter your secret number now.");
BigInteger a = new BigInteger(stdin.next());
// Make A's calculation.
BigInteger resulta = g.modPow(a,p);
System.out.println("Person A sends to person B "+resulta+".");
// Get B's secret number.
System.out.println("Person B: enter your secret number now.");
BigInteger b = new BigInteger(stdin.next());
// Make B's calculation.
BigInteger resultb = g.modPow(b,p);
System.out.println("Person B sends to person A "+resultb+".");
BigInteger KeyACalculates = resultb.modPow(a,p);
BigInteger KeyBCalculates = resulta.modPow(b,p);
// Print out the Key A calculates.
System.out.println("A takes "+resultb+" raises it to the power "+a+" mod "+p);
System.out.println("The Key A calculates is "+KeyACalculates+".");
// Print out the Key B calculates.
System.out.println("B takes "+resulta+" raises it to the power "+b+" mod "+p);
System.out.println("The Key B calculates is "+KeyBCalculates+".");
}
public static BigInteger getNextPrime(String ans) {
BigInteger test = new BigInteger(ans);
while (!test.isProbablePrime(99))
test = test.add(one);
return test;
}
}
最佳答案
由于评论太长...
Diffie-hellman 仅用于使用质数数学问题通过不 protected 连接进行 key 交换。它用于使用公钥和私钥初始化异步加密(如早期用于 SSL/TLS 的那样)。
除非需要作为练习(您应该添加作业或练习标签),否则不要自己实现此类安全内容,请使用现有的、经过良好测试的库。 Java 内置了对 SSL 的支持(也许使用其他 key 交换方法):SSLContext
尽管如此,您可以使用这些数字来派生公钥和私钥,但是,您必须确保它们确实很大(而不仅仅是 isProbablePrime
)素数,这会变得很慢与BigInteger
。
要连接客户端和服务器,请从 Socket 开始。但再次声明,如果这不是练习,您很可能会受到攻击(黑客攻击、DDOS 攻击……),您最好使用现有的、经过良好测试和强化的服务器。
关于java - java 中带有 diffie-hellman 的 ftp 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20774631/
一些快速背景。我使用 rclone 将数据传输到 SFTP 服务器。 rclone 是用 Golang 编写的,并在底层使用 lib crypto。当我们尝试与 SFTP 服务器建立 ssh 连接时,
我将 FIPS 186-3 推荐的曲线用于 Diffie-Hellman 椭圆曲线。我正在尝试确定私钥的最大长度,根据 RFC 5915 应该是: 天花板 (log2(n)/8) ,其中 n 是曲线的
我正在做一个项目,Alice 和 Bob 使用 Diffie-Hellman key 交换相互发送消息。让我陷入困境的是如何将他们正在使用的证书合并到其中,以便我可以获得他们的 secret 消息。
也许在这里问这个问题不太合适......无论如何,我正在尝试使用 gmp 库来实现 DH,但我遇到的问题是: 有一次,当我进行测试以观察输出时,尽管选择了较大的素数和私钥值: p 的十进制长度大约超过
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题? Update the question所以它是on-topic对于堆栈溢出。 9年前关闭。 Improve this que
我在 JavaCard 上遇到 DiffieHellman 问题。我有这门课: https://pastebin.com/2F2sQ2Pe (https://github.com/ASKGLab/DH
所以我正在尝试进行客户端-服务器 diffie hellman 加密。我使用这个:serverPublicKey = (int)Math.pow(generator,serverPrivateKey)
上下文 我在看这个视频DHE explained 它讲的是两个人如何在没有吸管的情况下交换 key 以了解更多信息。 根据视频实现 // INITIALIZERS (video's values)--
我有一个像这样的 Diffie–Hellman 安全类: public class AESSecurityCap { private PublicKey publicKey; KeyA
嗨,我正在尝试实现 Diffie–Hellman key 交换 public static Integer secret = 100000; public static BigInteger g =
我遇到了一个挑战,它与测试 friend 的加密过程有关。 这是一个Diffie-Hellman交换过程,这里是已知的变量/常量: P, G 我生成的私钥(可变) 我生成的公钥(变量) 收件人公钥(常
我有下面这行代码来生成私钥: int Xa = randomNo.nextInt(10000); int Ya = (int) Math.pow(G, Xa) % P; G 和 P 是静态数字。而 X
我正在尝试设计一种安全方案,用于加密 silverlight 客户端和我创建的 php web 服务之间的应用程序级数据。由于我正在处理一个公共(public)网站,因此我从服务中提取的信息是公开的,
所以我在阅读 this并对莱姆斯的回答感到惊讶。因为我认为情况正好相反。 所以,至于我的问题。为什么使用 diffie-hellman key 交换来确定共享 key 来加密/解密消息的程序(通常)不
是否有实现 diffie helman 的 Python 标准库? 我已经查看了 python pyopenssl 中的 openssl 包装器,但它没有涵盖它。 我也无法在 NaCl 或 crypt
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 关闭 9 年前。 Improve
我正在尝试实现 Diffie-Hellman key 交换。我对生成后如何使用 key 有点困惑。 如输出所示,2 个 key 是在 key 交换中使用相同的质数和基数生成的,并在生成 key 时交换
我需要进行单元测试来检查 Diffie-Hellman key 协议(protocol)协议(protocol)的实现是否正常,所以我需要测试向量来验证。问题是我在互联网上的任何地方都找不到它们。 R
Elliptic 曲线 diffie hellman 计算看起来与此处定义的标准曲线有什么不同: /* * The basic Diffie-Hell
我正在尝试创建一个可以使用加密数据将数据从客户端发送到服务器的应用程序。我已经用 Java 设置了一个基本的 Diffie Hellman key 交换,我只是想知道如何将其转换为 AES-128 k
我是一名优秀的程序员,十分优秀!