|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--codec.pkcs7.Signer
ATTENTION : if the strict DER Encoding shall be used, the function
setStrict(true) must be called right after instantiating the Object.
Signs a given Signable object, e.g. a
SignedData
or a SignedAndEnvelopedData.
| Field Summary | |
static int |
BUFFER_SIZE
The size of the buffer allocated for reading and signing data in case this is a detached signature file. |
protected ASN1ObjectIdentifier |
contentType_
The content type to be signed. |
protected MessageDigest |
digest_
The message digest engine that is used while signing is in progress. |
protected SignerInfo |
info_
The SignerInfo of the signer whose signature
generation is in progress. |
protected Signable |
target_
The Signable that is signed. |
protected boolean |
twostep_
true if signing is done with authenticated attributes. |
| Constructor Summary | |
Signer(Signable sigdat,
SignerInfo info,
PrivateKey key)
Creates an instance ready for signing. |
|
| Method Summary | |
void |
setStrict(boolean strictness)
|
void |
sign()
Completes the signing. |
void |
update()
Update operation. |
void |
update(byte[] b)
Update operation. |
void |
update(byte[] b,
int offset,
int len)
Update operation. |
void |
update(InputStream in)
Update operation for signing or verification. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int BUFFER_SIZE
protected Signable target_
Signable that is signed.protected SignerInfo info_
SignerInfo of the signer whose signature
generation is in progress.protected MessageDigest digest_
protected ASN1ObjectIdentifier contentType_
protected boolean twostep_
true if signing is done with authenticated attributes.| Constructor Detail |
public Signer(Signable sigdat,
SignerInfo info,
PrivateKey key)
throws GeneralSecurityException
sigdat - The Signable to which
SignerInfo
instances are added.info - The SignerInfo with the attributes that are
signed along with the data. This instance is later added
to the Signable
.key - The private key to use for signing.NoSuchAlgorithmException - if some required algorithm implementation cannot be
found.InvalidAlgorithmParameterException - if some parameters do not match the required algorithms.InvalidKeyException - if the public key does not match the signature algorithm.InvalidAttributeException - if the PKCS#9 ContentType attribute in the given
SignerInfo
does not match the content type
of the corresponding SignedData.| Method Detail |
public void setStrict(boolean strictness)
public void update(InputStream in)
throws SignatureException,
IOException
in - The input data to be signed or verified.IOException - if an I/O error occurs while reading from the given
stream.SignatureException - if this instance is not properly initialized.IOException - if an I/O exception occurs while reading from the input
stream.
public void update()
throws GeneralSecurityException
SignedData specified at creation time. If the
SignedData has no content then no updating takes place.
Note: updating must be done on the contents octets of the content
only, no identifier and length octets are hashed or signed (Verison 1.5).
Because the contents are already decoded by the
ContentInfo
we have to re-encode them according to DER. Unfortunately we cannot tell
how many identifier and length octets we have to skip without decoding
them first. There is a trick, though. We can briefly modify the tagging
of the contents to IMPLICIT tagging while encoding them. That way, the
identifier and length octets won't be encoded.
Note: Remember, the tagging will be changed for re-encoding
purposes. Custom content type instances must support this (it's supported
by default in all codec.asn1.* types).
If the content type is Data then there is no problem
because we can simply grab the contents octets from it.
public void update(byte[] b)
throws SignatureException
b - The input bytes.
public void update(byte[] b,
int offset,
int len)
throws SignatureException
b - The input bytes.offset - The offset into b at which the data to be
signed starts.len - The number of bytes starting with offset
to
be signed.
public void sign()
throws GeneralSecurityException
SignerInfo is added to the
target SignedData automatically.
Note: The signer's certificate is not added to the target
SignedData. This has to be done separately. Application
shall have full control over the embedding of certificates, because
certificates are likely to be distributed by other means as well (e.g.
LDAP). So there might not be a need to distibute them with
SignedData objects.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||