bouncycastle - Diffie Hellman key agreement generates different key every time JAVA -


i experiencing problem diffie hellman implementation. using code http://www.java2s.com/tutorial/java/0490__security/diffiehellmankeyagreement.htm

it example 1 book reading. can't understand why generatesecret() creates different key every keyagreement. have noticed function creates different keys if call same keyagreement twice! if has suggest glad!

thanks time!

i think part of example

private static biginteger g512 = new biginteger("1234567890", 16); private static biginteger p512 = new biginteger("1234567890", 16); 

is bogus. p needs prime , gneeds generator. when try running example exception. this seems more reasonable example (but haven't tested myself yet).

basically interesting input dh exchange (p,g) pair needs generated , must have unique properties. clearly, example above shows place holder values not produce correctly functioning algorithm (p can not equal g , p should prime, while in example divisible 10). example linked shows how use libraries generate correct (p, g) pair.

it worth noting dh parameter generation separate step generating secret key. while dh parameters private, not sensitive private key , can generated once , reused.

(edit: example)

algorithmparametergenerator paramgen = algorithmparametergenerator.getinstance("dh"); paramgen.init(512); // number of bits algorithmparameters params = paramgen.generateparameters(); dhparameterspec dhspec = params.getparameterspec(dhparameterspec.class);  biginteger p512 = dhspec.getp(); biginteger g512 = dhspec.getg(); int l = dhspec.getl(); ... 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -