Package com.globalmentor.security
Class DefaultNonce
java.lang.Object
com.globalmentor.security.DefaultNonce
- All Implemented Interfaces:
Nonce
A nonce that uses the current time, the date, a secret key, and a random number. This implementation stores information in the form:
time:privateKey:value
- Author:
- Garret Wilson
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionDefaultNonce
(String privateKey) Constructs a new nonce with generated values.protected
DefaultNonce
(String privateKey, Date time, long value) Constructs a nonce from existing information. -
Method Summary
Modifier and TypeMethodDescriptioncreateNonce
(String string) Creates a nonce from a formatted string.getTime()
long
getValue()
toString()
-
Field Details
-
DELIMITER
public static final char DELIMITERThe character that delimits fields in the nonce.- See Also:
-
DELIMITER_STRING
The string version of the character that delimits fields in the nonce. -
RANDOM
The shared random number factory.
-
-
Constructor Details
-
DefaultNonce
Constructs a new nonce with generated values.- Parameters:
privateKey
- The private key stored in the nonce.
-
DefaultNonce
Constructs a nonce from existing information.- Parameters:
privateKey
- The private key stored in the nonce. This key must not contain any occurrences of the delimiter.time
- The time stored in the nonce.value
- A random value held by the nonce.- Throws:
IllegalArgumentException
- if the private key contains an occurrence of the delimiter.
-
-
Method Details
-
getPrivateKey
- Specified by:
getPrivateKey
in interfaceNonce
- Returns:
- The private key stored in the nonce.
-
getTime
-
getValue
public long getValue()- Returns:
- A random value held by the nonce.
-
createNonce
Creates a nonce from a formatted string.- Parameters:
string
- The string containing the nonce.- Returns:
- A nonce containing values that would generate the same string as the one given.
- Throws:
SyntaxException
- if the given string does not have the correct format for this type of nonce.
-
toString
-