Package com.nettgryppa.security
Class HashCash
- java.lang.Object
- 
- com.nettgryppa.security.HashCash
 
- 
- All Implemented Interfaces:
- Comparable<HashCash>
 
 public class HashCash extends Object implements Comparable<HashCash> Class for generation and parsing of HashCash
 Copyright 2006 Gregory Rubin grrubin@gmail.com
 Permission is given to use, modify, and or distribute this code so long as this message remains attached
 Please see the spec at: http://www.hashcash.org/- Version:
- 1.1
- Author:
- grrubin@gmail.com
 
- 
- 
Field SummaryFields Modifier and Type Field Description static intDefaultVersion
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(HashCash other)Compares the value of two HashCashesbooleanequals(Object obj)Two objects are considered equal if they are both of type HashCash and have an identical string representationstatic longestimateTime(int value)Estimates how many milliseconds it would take to mint a cash of the specified value.static intestimateValue(int secs)Estimates what value (e.g.CalendargetDate()The minting dateMap<String,List<String>>getExtensions()Extra data encoded in the HashCashStringgetResource()The primary resource being protectedintgetValue()The value of the HashCash (e.g.intgetVersion()Which version of HashCash is used hereinthashCode()Implemented based on definition of equals()static HashCashmintCash(String resource, int value)Mints a version 1 HashCash using now as the datestatic HashCashmintCash(String resource, int value, int version)Mints a HashCash using now as the datestatic HashCashmintCash(String resource, Calendar date, int value)Mints a version 1 HashCashstatic HashCashmintCash(String resource, Calendar date, int value, int version)Mints a HashCashstatic HashCashmintCash(String resource, Map<String,List<String>> extensions, int value)Mints a version 1 HashCash using now as the datestatic HashCashmintCash(String resource, Map<String,List<String>> extensions, int value, int version)Mints a HashCash using now as the datestatic HashCashmintCash(String resource, Map<String,List<String>> extensions, Calendar date, int value)Mints a version 1 HashCashstatic HashCashmintCash(String resource, Map<String,List<String>> extensions, Calendar date, int value, int version)Mints a HashCashStringtoString()Returns the canonical string representation of the HashCash
 
- 
- 
- 
Field Detail- 
DefaultVersionpublic static final int DefaultVersion - See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
HashCashpublic HashCash(String cash) throws NoSuchAlgorithmException Parses and validates a HashCash.- Throws:
- NoSuchAlgorithmException- If SHA1 is not a supported Message Digest
 
 
- 
 - 
Method Detail- 
mintCashpublic static HashCash mintCash(String resource, int value) throws NoSuchAlgorithmException Mints a version 1 HashCash using now as the date- Parameters:
- resource- the string to be encoded in the HashCash
- Throws:
- NoSuchAlgorithmException- If SHA1 is not a supported Message Digest
 
 - 
mintCashpublic static HashCash mintCash(String resource, int value, int version) throws NoSuchAlgorithmException Mints a HashCash using now as the date- Parameters:
- resource- the string to be encoded in the HashCash
- version- Which version to mint. Only valid values are 0 and 1
- Throws:
- NoSuchAlgorithmException- If SHA1 is not a supported Message Digest
 
 - 
mintCashpublic static HashCash mintCash(String resource, Calendar date, int value) throws NoSuchAlgorithmException Mints a version 1 HashCash- Parameters:
- resource- the string to be encoded in the HashCash
- Throws:
- NoSuchAlgorithmException- If SHA1 is not a supported Message Digest
 
 - 
mintCashpublic static HashCash mintCash(String resource, Calendar date, int value, int version) throws NoSuchAlgorithmException Mints a HashCash- Parameters:
- resource- the string to be encoded in the HashCash
- version- Which version to mint. Only valid values are 0 and 1
- Throws:
- NoSuchAlgorithmException- If SHA1 is not a supported Message Digest
 
 - 
mintCashpublic static HashCash mintCash(String resource, Map<String,List<String>> extensions, int value) throws NoSuchAlgorithmException Mints a version 1 HashCash using now as the date- Parameters:
- resource- the string to be encoded in the HashCash
- extensions- Extra data to be encoded in the HashCash
- Throws:
- NoSuchAlgorithmException- If SHA1 is not a supported Message Digest
 
 - 
mintCashpublic static HashCash mintCash(String resource, Map<String,List<String>> extensions, int value, int version) throws NoSuchAlgorithmException Mints a HashCash using now as the date- Parameters:
- resource- the string to be encoded in the HashCash
- extensions- Extra data to be encoded in the HashCash
- version- Which version to mint. Only valid values are 0 and 1
- Throws:
- NoSuchAlgorithmException- If SHA1 is not a supported Message Digest
 
 - 
mintCashpublic static HashCash mintCash(String resource, Map<String,List<String>> extensions, Calendar date, int value) throws NoSuchAlgorithmException Mints a version 1 HashCash- Parameters:
- resource- the string to be encoded in the HashCash
- extensions- Extra data to be encoded in the HashCash
- Throws:
- NoSuchAlgorithmException- If SHA1 is not a supported Message Digest
 
 - 
mintCashpublic static HashCash mintCash(String resource, Map<String,List<String>> extensions, Calendar date, int value, int version) throws NoSuchAlgorithmException Mints a HashCash- Parameters:
- resource- the string to be encoded in the HashCash
- extensions- Extra data to be encoded in the HashCash
- version- Which version to mint. Only valid values are 0 and 1
- Throws:
- NoSuchAlgorithmException- If SHA1 is not a supported Message Digest
 
 - 
equalspublic boolean equals(Object obj) Two objects are considered equal if they are both of type HashCash and have an identical string representation
 - 
hashCodepublic int hashCode() Implemented based on definition of equals()
 - 
toStringpublic String toString() Returns the canonical string representation of the HashCash
 - 
getResourcepublic String getResource() The primary resource being protected
 - 
getDatepublic Calendar getDate() The minting date
 - 
getValuepublic int getValue() The value of the HashCash (e.g. how many leading zero bits it has)
 - 
getVersionpublic int getVersion() Which version of HashCash is used here
 - 
estimateTimepublic static long estimateTime(int value) throws NoSuchAlgorithmExceptionEstimates how many milliseconds it would take to mint a cash of the specified value.- NOTE1: Minting time can vary greatly in fact, half of the time it will take half as long)
- NOTE2: The first time that an estimation function is called it is expensive (on the order of seconds). After that, it is very quick.
 - Throws:
- NoSuchAlgorithmException- If SHA1 is not a supported Message Digest
 
 - 
estimateValuepublic static int estimateValue(int secs) throws NoSuchAlgorithmExceptionEstimates what value (e.g. how many bits of collision) are required for the specified length of time.- NOTE1: Minting time can vary greatly in fact, half of the time it will take half as long)
- NOTE2: The first time that an estimation function is called it is expensive (on the order of seconds). After that, it is very quick.
 - Throws:
- NoSuchAlgorithmException- If SHA1 is not a supported Message Digest
 
 - 
compareTopublic int compareTo(HashCash other) Compares the value of two HashCashes- Specified by:
- compareToin interface- Comparable<HashCash>
- Parameters:
- other-
- See Also:
- Comparable.compareTo(Object)
 
 
- 
 
-