|
IAIK PKCS#11 Provider Micro Edition version 1.0 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectiaik.pkcs.pkcs11.me.MessageDigest
Objects of this class calculate a hash values using the associated token.
A typical piece of code using this class may look like this.
Token token = ... long algorithm = MessageDigest.ALGORITHM_SHA_1; if (!token.supportsAlgorithm(algorithm)) { ... // token does not support this hash algorithm } MessageDigest tokenMessageDigest = token.getMessageDigest(algorithm); // feed in data, e.g. from a stream InputStream dataStream = ... byte[] buffer = new byte[1024]; int bytesRead; while ((bytesRead = dataStream.read(buffer)) >= 0) { tokenMessageDigest.update(buffer, 0, bytesRead); } byte[] digestValue = tokenMessageDigest.digest();The variable
digestValue
will hold the calculated hash value; e.g.
20 bytes (160 bit) for a SHA-1 hash value.
This class is not thread safe.
Token
,
Token.getMessageDigest(long)
,
Token.supportsAlgorithm(long, int)
Field Summary | |
static long |
ALGORITHM_MD2
The algorithm code constant for the MD2 hash algorithm as specified in RFC 1319. |
static long |
ALGORITHM_MD5
The algorithm code constant for the MD5 hash algorithm as specified in RFC 1321. |
static long |
ALGORITHM_RIPEMD128
The algorithm code constant for the RIPEMD-128 hash algorithm as specified in ISO/IEC 10118-3. |
static long |
ALGORITHM_RIPEMD160
The algorithm code constant for the RIPEMD-160 hash algorithm as specified in ISO/IEC 10118-3. |
static long |
ALGORITHM_SHA_1
The algorithm code constant for NIST's SHA-1 hash algorithm as specified in FIPS PUB 180-1. |
static long |
ALGORITHM_SHA_256
The algorithm code constant for NIST's SHA-256 hash algorithm as specified in FIPS PUB 180-2. |
static long |
ALGORITHM_SHA_384
The algorithm code constant for NIST's SHA-384 hash algorithm as specified in FIPS PUB 180-2. |
static long |
ALGORITHM_SHA_512
The algorithm code constant for NIST's SHA-512 hash algorithm as specified in FIPS PUB 180-2. |
Method Summary | |
byte[] |
digest()
Finish the hash calculation of the previously fed in data. |
static byte[] |
makeDigestInfo(byte[] hashValue,
long digestAlgorithm)
Create an encoded digest info structure for the specified hash algorithm and hash value. |
void |
update(byte[] data)
Feed a data piece of arbitrary length into the hash calculation. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final long ALGORITHM_SHA_1
public static final long ALGORITHM_MD2
public static final long ALGORITHM_MD5
public static final long ALGORITHM_RIPEMD128
public static final long ALGORITHM_RIPEMD160
public static final long ALGORITHM_SHA_256
public static final long ALGORITHM_SHA_384
public static final long ALGORITHM_SHA_512
Method Detail |
public static byte[] makeDigestInfo(byte[] hashValue, long digestAlgorithm) throws PKCS11Exception
ALGORITHM_
; e.g. ALGORITHM_SHA_1
.
This method is especially useful in for creating a RSA signature where the hash value is calculated separately to the RSA operation; e.g. hashing in software, RSA operation with padding on the token.
hashValue
- The raw hash value; e.g. 20 bytes for a SHA-1 hash value.digestAlgorithm
- The algorithm code of the hash algorithm;
e.g. ALGORITHM_SHA_1
.
PKCS11Exception
public void update(byte[] data) throws PKCS11RuntimeException
data
- The data to feed into the hash calculation.
PKCS11RuntimeException
digest()
public byte[] digest() throws PKCS11RuntimeException
PKCS11RuntimeException
update(byte[])
|
IAIK PKCS#11 Provider Micro Edition version 1.0 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |