比较java中的PublicKey对象 [英] Compare PublicKey object in java
本文介绍了比较java中的PublicKey对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个PublicKey对象。我想比较两者的相等性或使用java安全API或弹性城堡API来检查哪个是最新对象。我怎么能实现这个目标?
I have two PublicKey object.I want to compare both for equality or to check which is latest object using java security API or bouncy castle API.How can i achieve this?
推荐答案
您可以使用等于
if (!key.equals(copyKey)){
System.out.println("not equals!");
}
或检查密钥的哈希码
if (key.hashCode() != copyKey.hashCode())
{
System.out.println("public key hashCode check failed");
}
或比较两个公钥的十六进制字符串
or compare the hex string of the two public keys
String encodedKey1 = new String(Hex.encode(key1.getEncoded()));
String encodedKey2 = new String(Hex.encode(key2.getEncoded()));
if (!encodedKey1.equals(encodedKey2)){
System.out.println("not equals!");
}
您在Bouncy Castle Tests进行了大量的重要比较和检查样本,查看一些代码的 org.bouncycastle.jce.provider.test
包。 BC不是严格必要的,你可以与默认的java安全类进行比较。
You have a lot of key comparision and check samples at Bouncy Castle Tests, take a look at the org.bouncycastle.jce.provider.test
package for some code. BC is not strictly necesary you can do the comparision with the default java security classes.
这篇关于比较java中的PublicKey对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文