com.zoomlion.cloud.common.crypto.hash.Sha256Hash Maven / Gradle / Ivy
The newest version!
package com.zoomlion.cloud.common.crypto.hash;
import com.zoomlion.cloud.common.codec.Base64;
import com.zoomlion.cloud.common.codec.Hex;
/**
* Generates an SHA-256 Hash from a given input source with an optional salt and hash iterations.
*
* See the {@link SimpleHash SimpleHash} parent class JavaDoc for a detailed explanation of Hashing
* techniques and how the overloaded constructors function.
*
* JDK Version Note - Attempting to instantiate this class on JREs prior to version 1.4.0 will throw
* an {@link IllegalStateException IllegalStateException}
*
* @since 0.9
*/
public class Sha256Hash extends SimpleHash {
//TODO - complete JavaDoc
public static final String ALGORITHM_NAME = "SHA-256";
public Sha256Hash() {
super(ALGORITHM_NAME);
}
public Sha256Hash(Object source) {
super(ALGORITHM_NAME, source);
}
public Sha256Hash(Object source, Object salt) {
super(ALGORITHM_NAME, source, salt);
}
public Sha256Hash(Object source, Object salt, int hashIterations) {
super(ALGORITHM_NAME, source, salt, hashIterations);
}
public static Sha256Hash fromHexString(String hex) {
Sha256Hash hash = new Sha256Hash();
hash.setBytes(Hex.decode(hex));
return hash;
}
public static Sha256Hash fromBase64String(String base64) {
Sha256Hash hash = new Sha256Hash();
hash.setBytes(Base64.decode(base64));
return hash;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy