Implementing a Signature Class
Now
that we’ve seen how to use the Signature
class, we’ll look at how to implement our own class.
The techniques we’ll see here should be very familiar from our
other examples of implementing an engine in the security provider
architecture. In particular, since in 1.2 the
Signature
class extends its own SPI, we can
implement a single class that extends the
Signature
class.
To construct our subclass, we must use the following constructor:
- protected Signature(String algorithm)
This is the only constructor of the
Signature
class, so all subclasses of this class must use this constructor. The string passed to the constructor is the name that will be registered with the security provider.
Once we’ve constructed our engine object, we must implement the following methods in it:
- protected abstract void engineInitVerify(PublicKey pk)
Initialize the object to prepare it to verify a digital signature. If the public key does not support the correct algorithm or is otherwise corrupted, an
InvalidKeyException
is thrown.- protected abstract void engineInitSign(PrivateKey pk)
Initialize the object to prepare it to create a digital signature. If the private key does not support the correct algorithm or is otherwise corrupted, an
InvalidKeyException
is thrown.- protected abstract void engineUpdate(byte b) , protected abstract void engineUpdate(byte b[], int off, int len)
Add the given bytes to the data that is being accumulated for the signature. These methods are called by ...
Get Java Security now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.