public final class OtpTools extends Object
Modifier and Type | Class and Description |
---|---|
static class |
OtpTools.FormatType
Supported formatting modes for OTP.
|
static class |
OtpTools.ScrambleType
Supported scramble modes for OTP.
|
Modifier and Type | Method and Description |
---|---|
static SecureString |
formatOtp(OtpTools.FormatType mode,
SecureString otp)
Format the OTP with according provided mode.
|
static SecureString |
padOtpWithZero(SecureString otp,
int minLength)
left pad an OTP with Zero if needed.
|
static SecureString |
scrambleOtp(OtpTools.ScrambleType mode,
SecureString otp)
Compute a scrambled OTP from original OTP.
|
public static SecureString scrambleOtp(OtpTools.ScrambleType mode, SecureString otp)
mode
- - Specifies the mode of scrambling functionotp
- - Original otp. Length must greater or equal to 5 and only
digits are accepted.IllegalArgumentException
- When scramble type or otp is invalidpublic static SecureString formatOtp(OtpTools.FormatType mode, SecureString otp)
mode
- - Specifies the mode of formatting functionotp
- - original OTP
if mode is see OtpTools.FormatType.CAP
OTP length | Formatted OTP |
1 | X |
2 | XX |
3 | XXX |
4 | XXXX |
5 | XX XXX |
6 | XXX XXX |
7 | XXX XXXX |
8 | XXXX XXXX |
9 | XXX XXX XXX |
10 | XX XXXX XXXX |
11 | XXXXXXXXXXX |
12 | XXXXXXXXXXXX |
>12 | not changed |
IllegalArgumentException
- when the otp or format type is invalidIllegalArgumentException
- when the mode is CAP
and
the otp contains a non-digit character.public static SecureString padOtpWithZero(SecureString otp, int minLength)
otp
- OTP to pad.minLength
- The minimum length of the padded OTP. If minLength is lower than the otp length, no padding is added and a copy of otp is returned (so original one can be wiped).