com.nettgryppa.security
public class HashCash extends Object implements Comparable<HashCash>
Modifier and Type | Field and Description |
---|---|
static int |
DefaultVersion |
Constructor and Description |
---|
HashCash(String cash)
Parses and validates a HashCash.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(HashCash other)
Compares the value of two HashCashes
|
boolean |
equals(Object obj)
Two objects are considered equal if they are both of type HashCash and have an identical string representation
|
static long |
estimateTime(int value)
Estimates how many milliseconds it would take to mint a cash of the specified value.
|
static int |
estimateValue(int secs)
Estimates what value (e.g.
|
Calendar |
getDate()
The minting date
|
Map<String,List<String>> |
getExtensions()
Extra data encoded in the HashCash
|
String |
getResource()
The primary resource being protected
|
int |
getValue()
The value of the HashCash (e.g.
|
int |
getVersion()
Which version of HashCash is used here
|
static HashCash |
mintCash(String resource,
Calendar date,
int value)
Mints a version 1 HashCash
|
static HashCash |
mintCash(String resource,
Calendar date,
int value,
int version)
Mints a HashCash
|
static HashCash |
mintCash(String resource,
int value)
Mints a version 1 HashCash using now as the date
|
static HashCash |
mintCash(String resource,
int value,
int version)
Mints a HashCash using now as the date
|
static HashCash |
mintCash(String resource,
Map<String,List<String>> extensions,
Calendar date,
int value)
Mints a version 1 HashCash
|
static HashCash |
mintCash(String resource,
Map<String,List<String>> extensions,
Calendar date,
int value,
int version)
Mints a HashCash
|
static HashCash |
mintCash(String resource,
Map<String,List<String>> extensions,
int value)
Mints a version 1 HashCash using now as the date
|
static HashCash |
mintCash(String resource,
Map<String,List<String>> extensions,
int value,
int version)
Mints a HashCash using now as the date
|
String |
toString()
Returns the canonical string representation of the HashCash
|
public static final int DefaultVersion
public HashCash(String cash) throws NoSuchAlgorithmException
NoSuchAlgorithmException
- If SHA1 is not a supported Message Digestpublic static HashCash mintCash(String resource, int value) throws NoSuchAlgorithmException
resource
- the string to be encoded in the HashCashNoSuchAlgorithmException
- If SHA1 is not a supported Message Digestpublic static HashCash mintCash(String resource, int value, int version) throws NoSuchAlgorithmException
resource
- the string to be encoded in the HashCashversion
- Which version to mint. Only valid values are 0 and 1NoSuchAlgorithmException
- If SHA1 is not a supported Message Digestpublic static HashCash mintCash(String resource, Calendar date, int value) throws NoSuchAlgorithmException
resource
- the string to be encoded in the HashCashNoSuchAlgorithmException
- If SHA1 is not a supported Message Digestpublic static HashCash mintCash(String resource, Calendar date, int value, int version) throws NoSuchAlgorithmException
resource
- the string to be encoded in the HashCashversion
- Which version to mint. Only valid values are 0 and 1NoSuchAlgorithmException
- If SHA1 is not a supported Message Digestpublic static HashCash mintCash(String resource, Map<String,List<String>> extensions, int value) throws NoSuchAlgorithmException
resource
- the string to be encoded in the HashCashextensions
- Extra data to be encoded in the HashCashNoSuchAlgorithmException
- If SHA1 is not a supported Message Digestpublic static HashCash mintCash(String resource, Map<String,List<String>> extensions, int value, int version) throws NoSuchAlgorithmException
resource
- the string to be encoded in the HashCashextensions
- Extra data to be encoded in the HashCashversion
- Which version to mint. Only valid values are 0 and 1NoSuchAlgorithmException
- If SHA1 is not a supported Message Digestpublic static HashCash mintCash(String resource, Map<String,List<String>> extensions, Calendar date, int value) throws NoSuchAlgorithmException
resource
- the string to be encoded in the HashCashextensions
- Extra data to be encoded in the HashCashNoSuchAlgorithmException
- If SHA1 is not a supported Message Digestpublic static HashCash mintCash(String resource, Map<String,List<String>> extensions, Calendar date, int value, int version) throws NoSuchAlgorithmException
resource
- the string to be encoded in the HashCashextensions
- Extra data to be encoded in the HashCashversion
- Which version to mint. Only valid values are 0 and 1NoSuchAlgorithmException
- If SHA1 is not a supported Message Digestpublic boolean equals(Object obj)
public String toString()
public String getResource()
public Calendar getDate()
public int getValue()
public int getVersion()
public static long estimateTime(int value) throws NoSuchAlgorithmException
NoSuchAlgorithmException
- If SHA1 is not a supported Message Digestpublic static int estimateValue(int secs) throws NoSuchAlgorithmException
NoSuchAlgorithmException
- If SHA1 is not a supported Message Digestpublic int compareTo(HashCash other)
compareTo
in interface Comparable<HashCash>
other
- Comparable.compareTo(Object)