|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.pf.security.crypto.CryptoUtil
public class CryptoUtil
This utility class simplifies hashing passwords and particularly comparison of passwords.
Method Summary | |
---|---|
String |
asPlainText(String aString)
Returns the given string as it is if it does not start with a prefix in curly brackets (e.g. |
String |
base64EncodedWithPrefix(byte[] hash,
HashMechanism hashMechanism)
|
String |
base64HashedUTF8(String aString,
String hashMechanism)
Returns the given string UTF-8 char encoded, hashed with the specified hashing mechanism (e.g. |
byte[] |
computeHash(byte[] content,
CheckedHashAlgorithm hashAlgorithm)
Computes a hash value for the given input data using the specified hashing algorithm. |
byte[] |
computeHash(byte[] content,
String algorithm)
Computes a hash value for the given input data using the specified hashing algorithm. |
byte[] |
computeHash(String text,
org.pf.text.CheckedCharsetName charEncoding,
String algorithm)
Computes a hash value for the given text using the specified hashing algorithm. |
byte[] |
computeHash(String text,
String charEncoding,
String algorithm)
Computes a hash value for the given text using the specified hashing algorithm. |
byte[] |
computeUTF8Hash(String text,
String algorithmName)
Computes a hash value for the given text using UTF-8 character encoding an the specified hashing algorithm. |
byte[] |
createSHAhash(String aString)
Returns the SHA-1 hash representation of the given string in the current platform's character encoding. |
byte[] |
createSSHAhash(String aString)
Returns the SSHA hash representation of the given string |
byte[] |
createSSHAhash(String aString,
byte[] salt)
Returns the SSHA hash representation (SHA-1 based) of the given string. |
static CryptoUtil |
current()
Returns the only instance this class supports (design pattern "Singleton") |
String |
defaultEncrypted(String aString)
Returns the given string encrypted with the default algorithm and base64 encoded with a prefix naming the algorithm in curly brackets (e.g. |
boolean |
equals(String str1,
String str2)
Compares whether or not the two given strings are equal. |
boolean |
equals(String str1,
String str2,
org.pf.text.CheckedCharsetName charEncoding)
Compares whether or not the two given strings are equal. |
boolean |
equalsUTF8(String str1,
String str2)
Compares whether or not the two given strings are equal. |
byte[] |
generateSalt(int length)
Generates a random salt with the specified length. |
byte[] |
generateSalt20()
Generates a random salt with the default length of 20. |
String |
hashed(byte[] data,
HashMechanism hashMechanism)
Returns the given data hashed with the specified hashing mechanism (e.g. |
String |
hashedUTF8(String aString,
HashMechanism hashMechanism)
Returns the given string UTF-8 char encoded, hashed with the specified hashing mechanism (e.g. |
String |
hashedUTF8(String aString,
String hashMechanismName)
Returns the given string UTF-8 char encoded, hashed with the specified hashing mechanism (e.g. |
String |
shaEncrypted(String aString)
Returns the given string SHA encrypted and base64 encoded with a prefix "{SHA}". |
String |
sshaEncrypted(String aString)
Returns the given string SSHA encrypted and base64 encoded with a prefix "{SSHA}". |
String |
sshaEncrypted(String aString,
byte[] salt)
Returns the given string SSHA encrypted and base64 encoded with a prefix "{SSHA}". |
byte[] |
xor1(String string)
Returns the byte array containing the xor encoded representation of the given input string. |
String |
xor1Encrypted(String aString)
Returns the given string XOR1 encrypted and base64 encoded with a prefix "{XOR1}". |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static CryptoUtil current()
public String asPlainText(String aString)
aString
- The string to return or to convert into plain text
public String sshaEncrypted(String aString)
aString
- The string to be encryptedpublic String sshaEncrypted(String aString, byte[] salt)
aString
- The string to be encryptedsalt
- The salt valuepublic String shaEncrypted(String aString)
aString
- The string to be encryptedpublic String base64HashedUTF8(String aString, String hashMechanism)
CryptoConstants.SHA_2_384_NAME
)
and base64 encoded with a prefix (e.g. "{SHA256}) for the used mechanism".
Finally the whole string gets base64 encoded and returned.
aString
- The string to be hashed.hashMechanism
- The hashing mechanism to be used (Not algorithm names!).
See CryptoConstants.SHA_1_NAME
.
CryptoRuntimeException
- If the specified mechanism is not supported.public String hashedUTF8(String aString, String hashMechanismName)
CryptoConstants.SHA_2_512_NAME
)
and base64 encoded with a prefix (e.g. "{SHA256}) for the used mechanism".
aString
- The string to be hashed.hashMechanismName
- The hashing mechanism to be used (Not algorithm names!). See CryptoConstants
.
CryptoRuntimeException
- If the specified mechanism is not supported.public String hashedUTF8(String aString, HashMechanism hashMechanism)
HashMechanism.SALTED_SHA_2_256
)
and base64 encoded with a prefix (e.g. "{SSHA256}") for the used mechanism.
aString
- The string to be hashed.hashMechanism
- The hashing mechanism to be used.
CryptoRuntimeException
- If the specified mechanism is not supported.public String hashed(byte[] data, HashMechanism hashMechanism)
HashMechanism.SALTED_SHA_2_512
)
and base64 encoded with a prefix (e.g. "{SSHA512}") for the used mechanism.
data
- The data to be hashed.hashMechanism
- The hashing mechanism to be used.
CryptoRuntimeException
- If the specified mechanism is not supported.public String base64EncodedWithPrefix(byte[] hash, HashMechanism hashMechanism)
public String xor1Encrypted(String aString)
aString
- The string to be encryptedpublic String defaultEncrypted(String aString)
Currently it uses the XOR encryption.
public boolean equals(String str1, String str2)
The sting character encoding used here is the platform's default encoding.
public boolean equalsUTF8(String str1, String str2)
The sting character encoding used here is the platform's default encoding.
public boolean equals(String str1, String str2, org.pf.text.CheckedCharsetName charEncoding)
str1
- First string to compare with second.str2
- Second string to compare with first.charEncoding
- The character encoding used to convert strings to byte arrays.public byte[] xor1(String string)
public byte[] createSSHAhash(String aString)
public byte[] createSSHAhash(String aString, byte[] salt)
aString
- the string to be hashed.salt
- the salt value for SSHA.public byte[] createSHAhash(String aString)
public byte[] computeHash(byte[] content, String algorithm)
content
- The content to be hashed (must not be null).algorithm
- The name of the has algorithm (see CryptoConstants
). Must not be null.
CryptoRuntimeExcption
- If the given algorithm is not supported.public byte[] computeHash(byte[] content, CheckedHashAlgorithm hashAlgorithm)
content
- The content to be hashed (must not be null).hashAlgorithm
- The hash mechanism to use. Must not be null.
CryptoRuntimeExcption
- If the given algorithm is not supported.public byte[] computeHash(String text, String charEncoding, String algorithm)
text
- The content to be hashed (must not be null).charEncoding
- The character encoding to be used when converting the given text to bytes.algorithm
- The name of the has algorithm (see CryptoConstants
). Must not be null.
CryptoRuntimeExcption
- If the given charEncoding or algorithm is not supported.public byte[] computeHash(String text, org.pf.text.CheckedCharsetName charEncoding, String algorithm)
text
- The content to be hashed (must not be null).charEncoding
- The character encoding to be used when converting the given text to bytes.algorithm
- The name of the has algorithm (see CryptoConstants
). Must not be null.
CryptoRuntimeExcption
- If the given charEncoding or algorithm is not supported.public byte[] computeUTF8Hash(String text, String algorithmName)
text
- The content to be hashed (must not be null).algorithmName
- The name of the has algorithm (see CryptoConstants
). Must not be null.
CryptoRuntimeExcption
- If the given charEncoding or algorithm is not supported.public byte[] generateSalt(int length)
length
- The length of the salt to be generated.
public byte[] generateSalt20()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |