use of com.google.showcase.v1beta1.Sequence in project jss by dogtagpki.
the class SafeBag method encode.
@Override
public void encode(Tag implicitTag, OutputStream ostream) throws IOException {
SEQUENCE seq = new SEQUENCE();
seq.addElement(bagType);
seq.addElement(new EXPLICIT(new Tag(0), bagContent));
if (bagAttributes != null) {
seq.addElement(bagAttributes);
}
seq.encode(implicitTag, ostream);
}
use of com.google.showcase.v1beta1.Sequence in project jss by dogtagpki.
the class SignerInfo method encode.
@Override
public void encode(Tag tag, OutputStream ostream) throws IOException {
SEQUENCE sequence = new SEQUENCE();
sequence.addElement(version);
sequence.addElement(signerIdentifier);
sequence.addElement(digestAlgorithm);
if (signedAttributes != null) {
sequence.addElement(new Tag(0), signedAttributes);
}
sequence.addElement(digestEncryptionAlgorithm);
sequence.addElement(encryptedDigest);
if (unsignedAttributes != null) {
sequence.addElement(new Tag(1), unsignedAttributes);
}
sequence.encode(tag, ostream);
}
use of com.google.showcase.v1beta1.Sequence in project jss by dogtagpki.
the class SignerInfo method verifyWithoutSignedAttributes.
/**
* Verifies that the message digest passed in, when encrypted with the
* given public key, matches the encrypted digest in the SignerInfo.
*/
private void verifyWithoutSignedAttributes(byte[] messageDigest, OBJECT_IDENTIFIER contentType, PublicKey pubkey) throws NotInitializedException, NoSuchAlgorithmException, InvalidKeyException, TokenException, SignatureException {
if (!contentType.equals(ContentInfo.DATA)) {
// to go into signedAttributes.
throw new SignatureException("Content-Type is not DATA, but there are" + " no signed attributes");
}
SignatureAlgorithm sigAlg = SignatureAlgorithm.fromOID(digestEncryptionAlgorithm.getOID());
CryptoToken token = CryptoManager.getInstance().getInternalCryptoToken();
Signature sig;
byte[] toBeVerified;
if (sigAlg.getRawAlg() == SignatureAlgorithm.RSASignature) {
// create DigestInfo structure
SEQUENCE digestInfo = createDigestInfo(messageDigest, false);
toBeVerified = ASN1Util.encode(digestInfo);
sig = token.getSignatureContext(sigAlg.getRawAlg());
} else {
toBeVerified = messageDigest;
sig = token.getSignatureContext(sigAlg);
}
sig.initVerify(pubkey);
sig.update(toBeVerified);
if (sig.verify(encryptedDigest.toByteArray())) {
// success
return;
} else {
throw new SignatureException("Encrypted message digest parameter does not " + "match encrypted digest in SignerInfo");
}
}
use of com.google.showcase.v1beta1.Sequence in project jss by dogtagpki.
the class MacData method encode.
@Override
public void encode(Tag implicitTag, OutputStream ostream) throws IOException {
SEQUENCE seq = new SEQUENCE();
seq.addElement(mac);
seq.addElement(macSalt);
if (!macIterationCount.equals(new INTEGER(DEFAULT_ITERATIONS))) {
// 1 is the default, only include this element if it is not
// the default
seq.addElement(macIterationCount);
}
seq.encode(implicitTag, ostream);
}
use of com.google.showcase.v1beta1.Sequence in project jss by dogtagpki.
the class CertRepContent method encode.
@Override
public void encode(Tag implicitTag, OutputStream ostream) throws IOException {
SEQUENCE encoding = new SEQUENCE();
// create sequence of certificates
if (caPubs != null) {
SEQUENCE certs = new SEQUENCE();
for (int i = 0; i < caPubs.length; i++) {
certs.addElement(new ANY(SEQUENCE.TAG, caPubs[i]));
}
encoding.addElement(new Tag(1), certs);
}
encoding.addElement(response);
encoding.encode(implicitTag, ostream);
}
Aggregations