hashcode

HMAC security - Is the security of the HMAC based on SHA-1 affected by the collisions attacks on SHA-1?

筅森魡賤 提交于 2019-12-30 04:02:28
问题 Is the security of the HMAC based on SHA-1 affected by the collisions attacks on SHA-1? 回答1: The security implications of HMAC are described in detail in the security section of the RFC. In a nutshell, a very strong attack indeed is required before the security of the HMAC is threatened; the existing collision attacks on SHA-1 certainly don't constitute such. HMAC is specifically designed to make attacks difficult, and ordinary collision attacks won't generally suffice: The security of the

Google App Engine, JDO, and equals/hashCode

拜拜、爱过 提交于 2019-12-30 03:09:29
问题 I've got an app in Google App Engine that was working fine. I realized that one on of my JDO-enhanced objects that I forgot to implement equals and hashCode (I need to use the object in a set). So I did. I didn't really do anything special in these implementations, in fact I just used Eclipse to generate them. Like so: @PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) private Long id; @Persistent private String appleId; @Override public int hashCode() { final int prime =

java - what happens if hashCode is not overriden? [duplicate]

大憨熊 提交于 2019-12-30 02:28:35
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: what is an objects hashcode Let's say that I create an object, called Employee which has id, firstName, lastName and email for instance variables and corresponding setter/getter methods. How is hashCode() calculated if I don't override hashCode() in Employee object when it is stored in collection objects? 回答1: If you don't override hashcode() then the default implementation in Object class will be used by

is it incorrect to define an hashcode of an object as the sum, multiplication, whatever, of all class variables hashcodes?

江枫思渺然 提交于 2019-12-30 02:20:07
问题 Let's say I have the following class: class ABC { private int myInt = 1; private double myDouble = 2; private String myString = "123"; private SomeRandomClass1 myRandomClass1 = new ... private SomeRandomClass2 myRandomClass2 = new ... //pseudo code public int myHashCode() { return 37 * myInt.hashcode() * myDouble.hashCode() * ... * myRandomClass.hashcode() } } Would this be a correct implementation of hashCode? This is not how I usually do it(I tend to follow Effective Java's guide-lines) but

java中hashcode()和equals()的详解

*爱你&永不变心* 提交于 2019-12-30 02:10:45
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 今天下午研究了半天hashcode()和equals()方法,终于有了一点点的明白,写下来与大家分享(zhaoxudong 2008.10.23晚21.36)。 1. 首先equals()和hashcode()这两个方法都是从object类中继承过来的。 equals()方法在object类中定义如下: public boolean equals(Object obj) { return (this == obj); } 很明显是对两个对象的地址值进行的比较(即比较引用是否相同)。但是我们必需清楚,当String 、Math、还有Integer、Double。。。。等这些封装类在使用equals()方法时,已经覆盖了object类的equals()方法。比如在String类中如下: public boolean equals(Object anObject) { if (this == anObject) { return true; } if (anObject instanceof String) { String anotherString = (String)anObject; int n = count; if (n == anotherString.count) { char v1[] =

Set集合、Map集合

巧了我就是萌 提交于 2019-12-30 00:01:30
1、HashSet 集合 ● 特点: 底层数据结构:哈希表;存储、取出比较快;线程不安全,运行速度快(HashSet的底层是用HashMap实现的,因此查询效率较高,由于采用hashCode算法直接确定元素的内存地址,增删效率也挺高的) ● HashSet集合存储数据的结构(哈希表) 哈希表底层使用的也是数组机制,数组中也存放对象,而这些对象往数组中存放时的位置比较特殊,当需要把这些对象给数组中存放时,那么会根据这些对象的特有数据结合相应的算法,计算出这个对象在数组中的位置,然后把这个对象存放在数组中。而这样的数组就称为哈希数组,即就是哈希表。 当向哈希表中存放元素时,需要根据元素的特有数据结合相应的算法,这个算法其实就是Object类中的hashCode方法。由于任何对象都是Object类的子类,所以任何对象有拥有这个方法。即就是在给哈希表中存放对象时,会调用对象的hashCode方法,算出对象在表中的存放位置,这里需要注意,如果两个对象hashCode方法算出结果一样,这样现象称为哈希冲突,这时会调用对象的equals方法,比较这两个对象是不是同一个对象,如果equals方法返回的是true,那么就不会把第二个对象存放在哈希表中,如果返回的是false,就会把这个值存放在哈希表中。 总结:保证HashSet集合元素的唯一

Set<E> 接口简明

ε祈祈猫儿з 提交于 2019-12-29 14:46:31
java. util. Set 接口 Set 接口中的方法和 Collection 中方法一致的。Set 接口取出方式只有一种, 迭代器 。 HashSet : 底层数据结构是哈希表,线程 是不同步的 。 无序,高效;HashSet 集合保证元素唯一性 :通过元素的 hashCode 方法,和 equals 方法完成的。当元素的 hashCode 值相同时,才继续判断元素的 equals 是否为 true。如果为 true,那么视为相同元素,不存。如果为 false,那么存储。如果 hashCode 值不同,那么不判断 equals,从而提高对象比较的速度。 LinkedHashSet : 有序,hashset 的子类。 TreeSet : 对 Set 集合中的元素的进行指定顺序的排序。 不同步 。TreeSet 底层的数据结构就是二叉树。 对于ArrayList 集合,判断元素是否存在,或者删元素的依据都是 equals 方法。 对于HashSet 集合,判断元素是否存在,或者删除元素,依据的是 hashCode 方法和 equals 方法。 TreeSet: 用于对 Set 集合进行元素的指定顺序排序,排序需要依据元素自身具备的比较性。 如果元素不具备比较性,在运行时会抛出 ClassCastException 异常。 所以元素需要实现 Comparable 接口

Why might a System.String object not cache its hash code?

和自甴很熟 提交于 2019-12-29 04:27:12
问题 A glance at the source code for string.GetHashCode using Reflector reveals the following (for mscorlib.dll version 4.0): public override unsafe int GetHashCode() { fixed (char* str = ((char*) this)) { char* chPtr = str; int num = 0x15051505; int num2 = num; int* numPtr = (int*) chPtr; for (int i = this.Length; i > 0; i -= 4) { num = (((num << 5) + num) + (num >> 0x1b)) ^ numPtr[0]; if (i <= 2) { break; } num2 = (((num2 << 5) + num2) + (num2 >> 0x1b)) ^ numPtr[1]; numPtr += 2; } return (num +

Using auto generated id of Hibernate entity object in the equals and hashcode methods

我怕爱的太早我们不能终老 提交于 2019-12-29 00:45:11
问题 Lovely equals and hashcode, all the theory is here and also here I have taken the decision to use the auto-generated id within equals() and hashcode() in a number of my hibernate entity/domain objects. However, a number of websites say you should never do this due to the risk of persisting an object to the database for the first time whilst it is in the process of being compared or using hashcode. My point of view is that in most use cases this is much more unlikely than any other field being

toString(), equals(), and hashCode() in an interface

白昼怎懂夜的黑 提交于 2019-12-28 11:48:09
问题 So, I have an interface with a bunch of methods that need to be implemented, the method names are irrelevant. The objects that implement this interface are often put into collections, and also have a special toString() format that I want them to use. So, I thought it would be convenient to put hashCode(), equals(), and toString() into the interface, to make sure that I remember to override the default method for these. But when I added these methods to the interface, the IDE/Compiler doesn't