Diffie-Hellman对称键显示问题

时间:2021-05-22 18:25:45

I am generating Symmetric-keys by using bouncy castle Diffie-Hellman key exchange protocol, but when I display my generated Secret then it gives me the following error

我通过使用充气城堡Diffie-Hellman密钥交换协议生成对称密钥,但是当我显示我生成的秘密时它会给我以下错误

java.lang.IllegalStateException: Key agreement has not been completed yet

java.lang.IllegalStateException:密钥协议尚未完成

Assume from the below code that keys agreement process has be successfully completed and also from the hashes it confirms that both keys are the similar.

从下面的代码中假设密钥协商过程已经成功完成,并且从散列中确认两个密钥都是相似的。

    MessageDigest   hash = MessageDigest.getInstance("SHA1");
    byte[] aShared = hash.digest(aKeyAgree.generateSecret());
    byte[] bShared = hash.digest(bKeyAgree.generateSecret());
    System.out.println(Arrays.toString(aKeyAgree.generateSecret()));

1 个解决方案

#1


2  

It's probably simply that calling aKeyAgree.generateSecret() twice is the issue. The key agreement should be performed just once. If you want to print the result you need to store it in a (temporary) variable instead.

可能只是两次调用aKeyAgree.generateSecret()是个问题。密钥协议应该只执行一次。如果要打印结果,则需要将其存储在(临时)变量中。

#1


2  

It's probably simply that calling aKeyAgree.generateSecret() twice is the issue. The key agreement should be performed just once. If you want to print the result you need to store it in a (temporary) variable instead.

可能只是两次调用aKeyAgree.generateSecret()是个问题。密钥协议应该只执行一次。如果要打印结果,则需要将其存储在(临时)变量中。