public class CryptoUtil extends Object
Modifier and Type | Field and Description |
---|---|
static String |
BASE16_ENCODING |
static String |
BASE64_ENCODING |
static String |
RFC2617_ENCODING |
Constructor and Description |
---|
CryptoUtil() |
Modifier and Type | Method and Description |
---|---|
static Object |
accessSealedObject(String cipherAlgorithm,
Object key,
byte[] cipherIV,
Object obj) |
static byte[] |
calculatePasswordHash(String username,
char[] password,
byte[] salt)
Cacluate the SRP RFC2945 password hash = H(salt | H(username | ':' | password))
where H = SHA secure hash.
|
static byte[] |
calculateVerifier(String username,
char[] password,
byte[] salt,
BigInteger N,
BigInteger g)
Calculate x = H(s | H(U | ':' | password)) verifier
v = g^x % N
described in RFC2945.
|
static byte[] |
calculateVerifier(String username,
char[] password,
byte[] salt,
byte[] Nb,
byte[] gb)
Calculate x = H(s | H(U | ':' | password)) verifier
v = g^x % N
described in RFC2945.
|
static MessageDigest |
copy(MessageDigest md) |
static Object |
createCipher(String cipherAlgorithm) |
static String |
createPasswordHash(String hashAlgorithm,
String hashEncoding,
String hashCharset,
String username,
String password)
Calculate a password hash using a MessageDigest.
|
static String |
createPasswordHash(String hashAlgorithm,
String hashEncoding,
String hashCharset,
String username,
String password,
DigestCallback callback)
Calculate a password hash using a MessageDigest.
|
static Object |
createSealedObject(String cipherAlgorithm,
Object key,
byte[] cipherIV,
Serializable data) |
static Object |
createSecretKey(String cipherAlgorithm,
Object key)
Use reflection to create a javax.crypto.spec.SecretKeySpec to avoid
an explicit reference to SecretKeySpec so that the JCE is not needed
unless the SRP parameters indicate that encryption is needed.
|
static String |
encodeBase16(byte[] bytes)
Hex encoding of hashes, as used by Catalina.
|
static String |
encodeBase64(byte[] bytes)
BASE64 encoder implementation.
|
static String |
encodeRFC2617(byte[] data)
3.1.3 Representation of digest values
An optional header allows the server to specify the algorithm used to create
the checksum or digest.
|
static byte[] |
fromb64(String str) |
static byte[] |
generateSeed(int numBytes)
Returns the given number of seed bytes, computed using the seed
generation algorithm that this class uses to seed itself.
|
static Random |
getPRNG() |
static boolean |
hasUnlimitedCrypto()
From Appendix E of the JCE ref guide, the xaximum key size
allowed by the "Strong" jurisdiction policy files allows a maximum Blowfish
cipher size of 128 bits.
|
static void |
init() |
static void |
init(byte[] prngSeed) |
static MessageDigest |
newDigest() |
static void |
nextBytes(byte[] bytes)
Generates random bytes and places them into a user-supplied byte
array.
|
static double |
nextDouble()
Returns the next pseudorandom, uniformly distributed double value
between 0.0 and 1.0 from this random number generator's sequence.
|
static long |
nextLong()
Returns the next pseudorandom, uniformly distributed long value from
this random number generator's sequence.
|
static byte[] |
sessionKeyHash(byte[] number)
Perform an interleaved even-odd hash on the byte string
|
static String |
tob64(byte[] buffer) |
static byte[] |
trim(byte[] in)
Treat the input as the MSB representation of a number,
and lop off leading zero elements.
|
static byte[] |
xor(byte[] b1,
byte[] b2,
int length) |
public static final String BASE64_ENCODING
public static final String BASE16_ENCODING
public static final String RFC2617_ENCODING
public static void init() throws NoSuchAlgorithmException
NoSuchAlgorithmException
public static void init(byte[] prngSeed) throws NoSuchAlgorithmException
NoSuchAlgorithmException
public static MessageDigest newDigest()
public static MessageDigest copy(MessageDigest md)
public static Random getPRNG()
public static double nextDouble()
public static long nextLong()
public static void nextBytes(byte[] bytes)
public static byte[] generateSeed(int numBytes)
public static byte[] calculatePasswordHash(String username, char[] password, byte[] salt)
public static byte[] calculateVerifier(String username, char[] password, byte[] salt, byte[] Nb, byte[] gb)
public static byte[] calculateVerifier(String username, char[] password, byte[] salt, BigInteger N, BigInteger g)
public static byte[] sessionKeyHash(byte[] number)
public static byte[] trim(byte[] in)
public static byte[] xor(byte[] b1, byte[] b2, int length)
public static String encodeRFC2617(byte[] data)
data
- - the raw MD5 hash datapublic static String encodeBase16(byte[] bytes)
public static String encodeBase64(byte[] bytes)
public static String createPasswordHash(String hashAlgorithm, String hashEncoding, String hashCharset, String username, String password)
hashAlgorithm
- - the MessageDigest algorithm namehashEncoding
- - either base64 or hex to specify the type of
encoding the MessageDigest as a string.hashCharset
- - the charset used to create the byte[] passed to the
MessageDigestfrom the password String. If null the platform default is
used.username
- - ignored in default versionpassword
- - the password string to be hashedpublic static String createPasswordHash(String hashAlgorithm, String hashEncoding, String hashCharset, String username, String password, DigestCallback callback)
hashAlgorithm
- - the MessageDigest algorithm namehashEncoding
- - either base64 or hex to specify the type of
encoding the MessageDigest as a string.hashCharset
- - the charset used to create the byte[] passed to the
MessageDigestfrom the password String. If null the platform default is
used.username
- - ignored in default versionpassword
- - the password string to be hashedcallback
- - the callback used to allow customization of the hash
to occur. The preDigest method is called before the password is added
and the postDigest method is called after the password has been added.public static String tob64(byte[] buffer)
public static byte[] fromb64(String str) throws NumberFormatException
NumberFormatException
public static boolean hasUnlimitedCrypto()
public static Object createSecretKey(String cipherAlgorithm, Object key) throws KeyException
KeyException
public static Object createCipher(String cipherAlgorithm) throws GeneralSecurityException
cipherAlgorithm
- GeneralSecurityException
public static Object createSealedObject(String cipherAlgorithm, Object key, byte[] cipherIV, Serializable data) throws GeneralSecurityException
GeneralSecurityException
public static Object accessSealedObject(String cipherAlgorithm, Object key, byte[] cipherIV, Object obj) throws GeneralSecurityException
GeneralSecurityException
Copyright © 2017 JBoss by Red Hat. All rights reserved.