diffie-hellman

How to use BouncyCastle's Diffie-Hellman in C#?

一个人想着一个人 提交于 2019-12-07 10:47:08
问题 I'm writing an app that'll exchange data between a phone and a Windows PC, and I want to protect the data sent with key generated with a Diffie-Hellman exchange. I'm trying to use BouncyCastle for that, but the almost non-existant documentation for the C# implementation has me stumped. What I want to know is: what's the workflow for generating a DH key and computing a shared key when the other side's key is received? (I'm assuming I can send my key as a string and I can work with the other

How to do Diffie Hellman Key Generation and retrieve raw key bytes in Java

时间秒杀一切 提交于 2019-12-07 06:36:49
问题 I am writing a test harness in java for an existing program. As part of this i need to generate a Diffie Hellman key pair and pass the public key to the other program in its raw (i.e unencoded bytes) form. I can successfully the key pair using the following code: KeyPairGenerator kpg = KeyPairGenerator.getInstance("DiffieHellman"); kpg.initialize(512); KeyPair dkp = kpg.generateKeyPair(); However, i cannot seem to retrieve the raw byte value of the keys :-( Calling dkp.getPublic().getEncoded(

Diffie-Hellman Private Key

試著忘記壹切 提交于 2019-12-06 07:02:04
问题 I have the line of code below to generate a private key: int Xa = randomNo.nextInt(10000); int Ya = (int) Math.pow(G, Xa) % P; G and P are static numbers. Whereas Xa is randomly generated. Every time I run the program, it gives me the same result for Ya . Is this correct for Diffie-Hellman? I thought the private key had to be changed every time the algorithm was run. 回答1: I think the problem may be that you are overflowing double with your exponentiation, resulting in infinity, resulting in

OpenSSL used fixed Values for Diffie Hellman Key generation

大城市里の小女人 提交于 2019-12-06 05:11:05
According to that piece of documentation: https://wiki.openssl.org/index.php/Diffie_Hellman#Using_the_Low_Level_APIs Using the Low level API's for Diffie Hellman (need to perform a group Key agreement). For simplicity I need to provide fixed values for Diffie Hellman p and g values for now I use the function DH_generate_parameters_ex but any solution using these options may add a communication overhead and there are fixed values for p and g for Diffie Hellman offering good security. So using the approach convention over configuration, how I can set fixed values especially the ones specified in

RFC 5683阅读笔记 PAK

穿精又带淫゛_ 提交于 2019-12-05 22:27:00
RFC5683阅读笔记 Password-Authenticated Key(PAK) Diffie-Hellman Exchange 摘要 Diffie-Hellman(简称DH)密钥交换是最早的密钥交换算法之一,使得通信双方能在非安全的信道中安全的交换密钥,用于加密后续的通信消息。 在本文档中提出了一种算法用于在未经身份鉴别的Diffie-Hellman算法中添加双向的身份鉴别,这种算法称为Password-Authenticated Key(PAK)交换,它允许双方在执行Diffie-Hellman密钥交换时进行身份鉴别。 文档认为这种协议足够安全可以抵挡所有的主动攻击和被动攻击,而且不允许任何的攻击者获得可以用于进行字典攻击的信息。 文档规定 A 代表实体Alice B 代表实体Bob Ra是指由A选择的随机秘密指数 Rb是指由B选择的随机秘密指数 Xab表示由B得出的值(X可能由A计算) Yba表示由A得出的值(Y可能由B计算) 当a除以b时,a mod b表示最小的非负余数 Hi(u)表示在字符串u上计算的商定函数(例如基于SHA-1,SHA-256等),各种H()充当独立的随机函数,H1(u)和H2(u)是关键推导函数,H3(u)、H4(u)和H5(u)是哈希函数。 s | t表示字符串S和T的串联 ^表示幂 乘、除和求幂运算都是针对一个p元域执行的,也就是说 a b

Securing an android application

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 21:55:08
I have 'secured' the communication between my android application and a tls server providing a financial transaction service, currently in development. The security credentials are stored in a BKS keystore included in the Android apk. The password to the keystore is visible in plain text in the application source: keyStore.load(is, "passwd".toCharArray()); I am concerned that if someone was to reverse engineer the app, they would be able to impersonate another user and compromise the security of the service. I was wondering whether there is a fault in my implementation, if anyone else has this

Doing ECDHE key exchange using C#

落爺英雄遲暮 提交于 2019-12-05 20:02:19
I am trying to do ECDHE key exchange over TLS 1.2 using .net. The server is responding with a server_key_exchange message, which begins with 04, so I guess it is unencrypted. From my understanding the first 32 bits of the message are considered as a value X, and the next 32 bits are considered as a value Y. Using these, and the elliptic curve (say secp256r1), the value of public key of server is created. I am referring to the following python code from OpenTLS : class ECDHE_RSA_Key_Exchange: def __init__(self, server_key_exchange): curve_code = bytes_to_hex(server_key_exchange[5:7]) print(

Generate EC Diffie-Hellman public and private key pair

半世苍凉 提交于 2019-12-05 19:26:13
I need to generate an EC Diffie Hellman key pair. I am using the secp256r1 named curve, and OpenSSL. This is what I have with me so far: unsigned char *ecdh(size_t *secret_len) { EVP_PKEY_CTX *pctx, *kctx; EVP_PKEY_CTX *ctx; unsigned char *secret; EVP_PKEY *pkey = NULL, *peerkey, *params = NULL; /* NB: assumes pkey, peerkey have been already set up */ /* Create the context for parameter generation */ if(NULL == (pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL))) printf("Error in EC key generation\n"); /* Initialise the parameter generation */ if(1 != EVP_PKEY_paramgen_init(pctx)) printf("Error in

How to use BouncyCastle's Diffie-Hellman in C#?

一笑奈何 提交于 2019-12-05 14:01:36
I'm writing an app that'll exchange data between a phone and a Windows PC, and I want to protect the data sent with key generated with a Diffie-Hellman exchange. I'm trying to use BouncyCastle for that, but the almost non-existant documentation for the C# implementation has me stumped. What I want to know is: what's the workflow for generating a DH key and computing a shared key when the other side's key is received? (I'm assuming I can send my key as a string and I can work with the other side's key as a string.) What objects/methods do I use in C# for that? Alright, after a lot of trial, I

How to do Diffie Hellman Key Generation and retrieve raw key bytes in Java

南楼画角 提交于 2019-12-05 10:29:28
I am writing a test harness in java for an existing program. As part of this i need to generate a Diffie Hellman key pair and pass the public key to the other program in its raw (i.e unencoded bytes) form. I can successfully the key pair using the following code: KeyPairGenerator kpg = KeyPairGenerator.getInstance("DiffieHellman"); kpg.initialize(512); KeyPair dkp = kpg.generateKeyPair(); However, i cannot seem to retrieve the raw byte value of the keys :-( Calling dkp.getPublic().getEncoded() returns a byte array but its of the Key in an x509 encoded format. Three possible ways forward occur