org.pf.security.crypto
Class HashedString

java.lang.Object
  extended by org.pf.security.crypto.HashedString

public class HashedString
extends Object

Container for a SHA hashed strings including salt for SSHA. Supports SHA-1 (160 bit) as well as SHA-2 (256, 383, 512 bit). SHA-2 224 bit is not supported before Java 8 or with a crypto provider explicitly added to the classpath.

Version:
2.0
Author:
Manfred Duchrow

Constructor Summary
HashedString(byte[] content, byte[] salt, HashMechanism mechanism)
           
HashedString(byte[] content, byte[] salt, String hashType)
           
HashedString(byte[] content, HashMechanism mechanism)
           
HashedString(byte[] content, String hashType)
           
HashedString(String string)
          Initialize the new instance with a hashed string.
 
Method Summary
 String asString()
          Returns the contents base64 with a curly bracket prefix that defines the used hashing mechanism.
 boolean isEqual(byte[] plainText)
          Compares the given plain text string with the hashed string.
 boolean isEqual(String string)
          Compares the given clear text string with the hashed value.
 boolean isEqualUTF8(String string)
          Compares the given clear text string with the hashed value (which was hashed as UTF-8).
 boolean isSalted()
          Returns true if the value is salted.
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HashedString

public HashedString(String string)
Initialize the new instance with a hashed string.

Parameters:
string - A base64 encoded hash of a string with a prefix (e.g. {SHA} or {SSHA} or {SHA256} )

HashedString

public HashedString(byte[] content,
                    String hashType)

HashedString

public HashedString(byte[] content,
                    HashMechanism mechanism)

HashedString

public HashedString(byte[] content,
                    byte[] salt,
                    String hashType)

HashedString

public HashedString(byte[] content,
                    byte[] salt,
                    HashMechanism mechanism)
Method Detail

isSalted

public boolean isSalted()
Returns true if the value is salted.


isEqualUTF8

public boolean isEqualUTF8(String string)
Compares the given clear text string with the hashed value (which was hashed as UTF-8). Returns true if the hash of the given string equals the hash in this object.


isEqual

public boolean isEqual(String string)
Compares the given clear text string with the hashed value. Returns true if the hash of the given string equals the hash in this object.


isEqual

public boolean isEqual(byte[] plainText)
Compares the given plain text string with the hashed string. Returns true if the hash of the given plain text equals the hash in this object.


asString

public String asString()
Returns the contents base64 with a curly bracket prefix that defines the used hashing mechanism.

Example: "{SSHA256}lKv8GwCDbjB6wvYroiAKaGZXUdWYgtYAnpQWLTrWHPUSzuooRrOT5Yp70mbNwfx0IziQ+g=="


toString

public String toString()
Overrides:
toString in class Object


Copyright © 2013 Manfred Duchrow Consulting & Software. All Rights Reserved.