public class ScramUtils extends Object
Modifier and Type | Class and Description |
---|---|
static class |
ScramUtils.NewPasswordByteArrayData
New password data in byte array format
|
static class |
ScramUtils.NewPasswordStringData
New password data in database friendly format, i.e.
|
Modifier and Type | Method and Description |
---|---|
static ScramUtils.NewPasswordStringData |
byteArrayToStringData(ScramUtils.NewPasswordByteArrayData ba)
Transforms NewPasswordByteArrayData into NewPasswordStringData into database friendly (string)
representation Uses Base64 to encode the byte arrays into strings
|
static byte[] |
computeHmac(byte[] key,
Mac hmac,
String string) |
static byte[] |
computeHmac(byte[] key,
String hmacName,
String string)
Computes HMAC byte array for given string
|
static Mac |
createHmac(byte[] keyBytes,
String hmacName)
Creates HMAC
|
static byte[] |
generateSaltedPassword(String password,
byte[] salt,
int iterationsCount,
Mac mac)
Generates salted password.
|
static boolean |
isNullOrEmpty(String string)
Checks if string is null or empty
|
static ScramUtils.NewPasswordByteArrayData |
newPassword(String passwordClearText,
byte[] salt,
int iterations,
MessageDigest messageDigest,
Mac mac)
Computes the data associated with new password like salted password, keys, etc
|
public static byte[] generateSaltedPassword(String password, byte[] salt, int iterationsCount, Mac mac) throws ScramException
password
- Clear form password, i.e. what user typedsalt
- Salt to be usediterationsCount
- Iterations for 'salting'mac
- HMAC to be usedScramException
public static Mac createHmac(byte[] keyBytes, String hmacName) throws NoSuchAlgorithmException, InvalidKeyException
keyBytes
- keyhmacName
- HMAC nameInvalidKeyException
- if internal error occur while working with SecretKeySpecNoSuchAlgorithmException
- if hmacName is not supported by the javapublic static byte[] computeHmac(byte[] key, String hmacName, String string) throws InvalidKeyException, NoSuchAlgorithmException
key
- keyhmacName
- HMAC namestring
- string for which HMAC will be computedInvalidKeyException
- if internal error occur while working with SecretKeySpecNoSuchAlgorithmException
- if hmacName is not supported by the javapublic static byte[] computeHmac(byte[] key, Mac hmac, String string) throws ScramException
ScramException
public static boolean isNullOrEmpty(String string)
string
- String to be testedpublic static ScramUtils.NewPasswordByteArrayData newPassword(String passwordClearText, byte[] salt, int iterations, MessageDigest messageDigest, Mac mac) throws ScramException
This method is supposed to be used by a server when user provides new clear form password. We don't want to save it that way so we generate salted password and store it along with other data required by the SCRAM mechanism
passwordClearText
- Clear form password, i.e. as provided by the usersalt
- Salt to be usediterations
- Iterations for 'salting'mac
- HMAC name to be usedmessageDigest
- Digest name to be usedScramException
public static ScramUtils.NewPasswordStringData byteArrayToStringData(ScramUtils.NewPasswordByteArrayData ba)
ba
- Byte array dataCopyright © 2021 The Apache Software Foundation. All rights reserved.