标签: diffie-hellman

为什么Curve25519参数错误却能正确计算密钥对?

.NET (Core 3.1) 似乎支持 ECC 中的自定义曲线。所以我定义了Curve25519,并通过以下代码生成密钥对:

using System;
using System.Security.Cryptography;

namespace Curve25519
{
    class Program
    {
        static void Main(string[] args)
        {
            ECCurve ecCurve = new ECCurve() // Curve25519, 32 bytes, 256 bit
            {
                CurveType = ECCurve.ECCurveType.PrimeMontgomery,
                B = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
                A = new byte[] …
Run Code Online (Sandbox Code Playgroud)

elliptic-curve diffie-hellman curve-25519 .net-core x25519

7
推荐指数
1
解决办法
1505
查看次数

如何在java 8中将DH密钥大小扩展到2048

我读了很多帖子说在java 8中可以将DH密钥大小扩展到2048.他们说可以通过将值jdk.tls.ephemeralDHKeySize改为:2048来从系统属性中 获取.我试图弄清楚在哪里和如何做到这一点,找不到.我在哪里可以找到这个变量或属性?哪个文件?路径?我正在使用Windows.

java security ssl diffie-hellman

6
推荐指数
1
解决办法
1万
查看次数

为什么在 Diffie-Hellman 密钥交换中使用素数?

Diffie-Hellman 密钥交换算法使用诸如2^8 mod nwheren是素数之类的操作。

使用质数而不是其他数字的原因是什么?

cryptography public-key-encryption diffie-hellman

6
推荐指数
1
解决办法
3832
查看次数

使用 WebCrypto 从 PBKDF2 生成 ECDH 密钥

\n

警告以下内容并非对将密码转换为 ECDH 密钥的认可。从高熵、加密安全的 PRNG 创建 ECDH 密钥。

\n
\n\n

我想获取一个秘密并从中生成 ECDH 公钥/私钥。

\n\n

在浏览器中,通常的方法是使用 PBKDF2(或其他确定性字节)在 WebCrypto 中生成 ECDH 公钥/私钥对。

\n\n

以下示例代码应该执行此操作,但它在 Chrome 中引发 DOM 异常:

\n\n
// Generate a random KDF key.\nconst priv = new Uint8Array(24)\ncrypto.getRandomValues(priv)\nconst kdfKey = await crypto.subtle.importKey(\n  \'raw\', priv, { name: \'PBKDF2\' }, false, [\'deriveKey\'])\n\n// Derive the ECDH key.\nconst salt = new Uint8Array(16)\nconst iterations = 2000\nconst hash = { name: \'SHA-512\' }\nconst curve = { name: \'ECDH\', namedCurve: \'P-384\' }\nconst usages = [\'deriveKey\']\n\ncrypto.getRandomValues(salt)\n\nconst ecdhKey = …
Run Code Online (Sandbox Code Playgroud)

javascript cryptography diffie-hellman

6
推荐指数
1
解决办法
2236
查看次数

如何构建高度安全的端到端加密 React Native 消息传递应用程序

我目前正在开发即时 React Native 消息传递应用程序,我想实现 E2EE(发送方和接收方之间的端到端加密)以提高安全性。我使用的库/框架是用于后端的 NodeJS、用于实时通信的 Socket.io、用于数据管理的 MongoDB 以及用于前端的 React Native。

在这一点上,我能够从发送者到服务器来回发送消息,然后再发送回接收者,但服务器实际上可以读取非常烦人的消息,因为我想将消息(加密)保存在我的数据库中并检索他们让用户看到他的历史。

最近我发现 Diffie-Hellman 密钥交换是在每个端点设备上生成共享密钥的一个很好的解决方案,但我不知道如何在我的应用程序中实现它。

我还发现大型消息应用程序(如 WhatsApp、Facebook Messenger、Signal 等)使用基于 X3DH(扩展三重 Diffie-Hellman)的信号协议,我想知道是否有可能实现这样一个好的我的 RN 应用程序中的东西。但问题是,即使在阅读了 Signal Protocol 的文档之后,我也无法弄清楚如何实现它。

总之,我的问题是如何在我的 RN 应用程序中实现信号协议并使用 Socket.io 发送和接收加密消息?如果由于某种原因这是不可能的,我如何自己实现 Diffie-Hellman 密钥交换?

感谢任何可以帮助我的人!

encryption websocket node.js diffie-hellman end-to-end-encryption

6
推荐指数
1
解决办法
2183
查看次数

OpenSSL 3 Diffie-Hellman 密钥交换 C++

在 OpenSSL3 之前,这很简单。

DH* dh = DH_new();

/* Parameters */
dh->p = BN_bin2bn(bin_p, bin_p_size, NULL);
dh->g = BN_bin2bn(bin_g, bin_g_size, NULL);

/* Private key generation */
BN_hex2bn(&dh->priv_key, hex_priv_key);

/* Public key generation */
DH_generate_key(dh);

/* Derive */
int shared_key_size = DH_compute_key(shared_key, peer_pub_key, dh);
Run Code Online (Sandbox Code Playgroud)

我正在尝试在新版本的 OpenSSL 中创建密钥,但它不起作用,因为 EVP_PKEY_generate 失败并出现错误:03000097:数字信封例程::操作未初始化

OSSL_PARAM_BLD* param_build = OSSL_PARAM_BLD_new();
OSSL_PARAM_BLD_push_BN(param_build, OSSL_PKEY_PARAM_FFC_P, p);
OSSL_PARAM_BLD_push_BN(param_build, OSSL_PKEY_PARAM_FFC_G, g);

OSSL_PARAM* params = OSSL_PARAM_BLD_to_param(param_build};

/* DH_new() */
EVP_PKEY_CTX* ctx = EVP_PKEY_CTX_new_from_name(nullptr, "DH", nullptr);
EVP_PKEY_keygen_init(ctx);

/* DH_generate_key */
EVP_PKEY* dh_key_pair = NULL;
EVP_PKEY_generate(ctx, &dh_key_pair, …
Run Code Online (Sandbox Code Playgroud)

c c++ openssl diffie-hellman

6
推荐指数
1
解决办法
2914
查看次数

为什么使用OpenSSL diffie hellman的关键不等?

我不知道为什么我的密钥在做这个难度的hellman交换示例时是不相等的.我在C中使用openssl库(openssl/dh.h).

它似乎非常简单,但由于某种原因,键不一样.我错过了什么?

有任何想法吗?谢谢!

    void hexprint(unsigned char *printBuf, int len)
    {
        int i;
        for(i = 0; i < len; i++)
        {
            printf("%x ", printBuf[i]);
        }
        printf("\n");
    }

    int main(int argc, char *argv[])
    {
        srand(time(NULL));
        DH *dh1;
        DH *dh2;
        unsigned char *dh_secret1;
        unsigned char *dh_secret2;
        dh1 = DH_generate_parameters(256, 2, NULL, NULL);
        dh2 = DH_generate_parameters(256, 2, NULL, NULL);

        DH_generate_key(dh1);
        DH_generate_key(dh2);

        dh_secret1 = malloc(DH_size(dh1));
        memset(dh_secret1, 0, DH_size(dh1));
        dh_secret2 = malloc(DH_size(dh2));
        memset(dh_secret2, 0, DH_size(dh2));

        DH_compute_key(dh_secret1, dh2->pub_key, dh1);
        DH_compute_key(dh_secret2, dh1->pub_key, dh2);

        printf("Secret Key 1: \n");
        hexprint(dh_secret1, …
Run Code Online (Sandbox Code Playgroud)

c openssl cryptography diffie-hellman

5
推荐指数
1
解决办法
2289
查看次数

Java Diffie-Hellman密钥交换

我正在尝试执行代码来执行Diffie-Hellman密钥交换.我从在线示例中获取代码(忘记现在的位置).我不得不导入bouncycastle.jar,我假设它一直在执行.

stacktrace截图

我的代码:

package testproject;

import java.math.BigInteger;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.MessageDigest;
import java.security.SecureRandom;
import java.security.Security;
import javax.crypto.KeyAgreement;
import javax.crypto.spec.DHParameterSpec;

public class KeyGen {

  private static BigInteger g512 = new BigInteger("1234567890", 16);
  //generates a random, non-negative integer for Base

  private static BigInteger p512 = new BigInteger("1234567890", 16);
  //generates a random, non-negative integer for Prime

  public static void main(String[] args) throws Exception {
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
    DHParameterSpec dhParams = new DHParameterSpec(p512, g512);
    //Specify parameters to use for the algorithm
    KeyPairGenerator keyGen = …
Run Code Online (Sandbox Code Playgroud)

java bouncycastle diffie-hellman

5
推荐指数
2
解决办法
1万
查看次数

具有BIGNUM(OpenSSL)与BigInteger(C#)的Diffie-Hellman

我正在使用OpenSSL库进行操作的嵌入式设备和使用方法计算秘密共享密钥生成的C#软件之间实现Diffie-Hellman密钥交换算法.BIGNUMSystem.Numerics.BigInteger

但在Alice和Bob交换密钥后,他们会计算出不同的共享秘密.

钥匙打印在每一侧(PubA, PrivA, PubB, PrivB, DHPrime, DHGenerator),我可以看到它们是相同的.

我怀疑有一个关于小/大字节序的问题,或者openssl不关心指数的负数,我不知道如何调试这些操作.我现在没有代码,但所有操作都保持简单,就像这样.

C#方面

BigInteger bintA = new BigInteger(baByteArrayReceived);
BigInteger bintb = new BigInteger(baRandomBobSecret);
BigInteger bintDHPrime = new BigInteger(baDHPrime2048);

BigInteger bintSharedSecret = bintA.ModPow(bintb,bintDHPrime);
Run Code Online (Sandbox Code Playgroud)

C方面

BIGNUM *bnB = BN_new();
BIGNUM *bna = BN_new();
BIGNUM *bnDHPrime = BN_new();
BIGNUM *bnResult = BN_new();
BN_CTX *bnctx = BN_CTX_new();

BN_bin2bn(baBReceived, 256,bnB);
BN_bin2bn(baRandomAliceSecret, 256,bna);
BN_bin2bn(baDHPrime2048, 256,bnDHPrime);

BN_mod_exp(bnResult,bnB,bna,bnDHPrime,bnctx);
Run Code Online (Sandbox Code Playgroud)

OpenSSL的C方法的一些附加信息:>

BIGNUM *BN_bin2bn(const uint8_t *in, size_t len, BIGNUM *ret);
Run Code Online (Sandbox Code Playgroud)

BN_bin2bn设置|*ret | 到| len |的值 来自| in …

c c# openssl biginteger diffie-hellman

5
推荐指数
1
解决办法
978
查看次数

如何检查我的服务器 Diffie-Hellman MODP 大小(位)并增加它?

再会,

我在 Linux Redhat 中有一个 WAS 自由服务器,并且我启用了唯一的 TLSv1.2。

我输入以下命令来获取服务器信息:

openssl s_client -connect 10.7.5.65:9443 -msg
Run Code Online (Sandbox Code Playgroud)

部分结果如下:

No client certificate CA names sent
Peer signing digest: SHA512
Server Temp Key: DH, 1024 bits
---
SSL handshake has read 1710 bytes and written 479 bytes
---
New, TLSv1/SSLv3, Cipher is DHE-RSA-AES128-GCM-SHA256
Server public key is 2048 bit
Secure Renegotiation IS supported
Run Code Online (Sandbox Code Playgroud)

我看到Server Temp Key值是 DH,1024 位,但也看到服务器公钥是 2048 位,请问我的 Diffie-Hellman MODP 大小(位)实际上是 1024 还是 2048?

还有那部分 ServerKeyExchange

<<< TLS 1.2 Handshake [length …
Run Code Online (Sandbox Code Playgroud)

linux openssl bit diffie-hellman redhat-openjdk

5
推荐指数
1
解决办法
2523
查看次数