use of org.mozilla.jss.netscape.security.util.DerOutputStream in project jss by dogtagpki.
the class X509CertInfo method encode.
/**
* Appends the certificate to an output stream.
*
* @param out An output stream to which the certificate is appended.
* @param ignoreCache Whether to ignore the internal cache when encoding.
* (the cache can easily become out of date).
*/
public void encode(OutputStream out, boolean ignoreCache) throws IOException, CertificateException {
if (ignoreCache || (rawCertInfo == null)) {
DerOutputStream tmp = new DerOutputStream();
emit(tmp);
rawCertInfo = tmp.toByteArray();
}
out.write(rawCertInfo);
}
use of org.mozilla.jss.netscape.security.util.DerOutputStream in project jss by dogtagpki.
the class X509CertInfo method emit.
/*
* Marshal the contents of a "raw" certificate into a DER sequence.
*/
private void emit(DerOutputStream out) throws CertificateException, IOException {
DerOutputStream tmp = new DerOutputStream();
// version number, iff not V1
version.encode(tmp);
// Encode serial number, issuer signing algorithm, issuer name
// and validity
serialNum.encode(tmp);
algId.encode(tmp);
issuer.encode(tmp);
interval.encode(tmp);
// Encode subject (principal) and associated key
subject.encode(tmp);
pubKey.encode(tmp);
// Encode issuerUniqueId & subjectUniqueId.
if (issuerUniqueId != null) {
issuerUniqueId.encode(tmp);
}
if (subjectUniqueId != null) {
subjectUniqueId.encode(tmp);
}
// Write all the extensions.
if (extensions != null) {
extensions.encode(tmp);
}
// Wrap the data; encoding of the "raw" cert is now complete.
out.write(DerValue.tag_Sequence, tmp);
}
use of org.mozilla.jss.netscape.security.util.DerOutputStream in project jss by dogtagpki.
the class X509Key method encode.
/*
* Produce SubjectPublicKey encoding from algorithm id and key material.
*/
static void encode(DerOutputStream out, AlgorithmId algid, byte[] key) throws IOException {
DerOutputStream tmp = new DerOutputStream();
algid.encode(tmp);
tmp.putBitString(key);
out.write(DerValue.tag_Sequence, tmp);
}
use of org.mozilla.jss.netscape.security.util.DerOutputStream in project jss by dogtagpki.
the class X509Key method encode.
/**
* Returns the DER-encoded form of the key as a byte array.
*
* @exception InvalidKeyException on encoding errors.
*/
public byte[] encode() throws InvalidKeyException {
if (encodedKey == null) {
try {
DerOutputStream out;
out = new DerOutputStream();
encode(out);
encodedKey = out.toByteArray();
} catch (IOException e) {
throw new InvalidKeyException("IOException : " + e.getMessage());
}
}
return copyEncodedKey(encodedKey);
}
use of org.mozilla.jss.netscape.security.util.DerOutputStream in project jss by dogtagpki.
the class RSAPSSAlgorithmParameters method encode.
private void encode(DerOutputStream out) throws IOException {
try (DerOutputStream tmp = new DerOutputStream();
DerOutputStream mgf = new DerOutputStream();
DerOutputStream seq1 = new DerOutputStream();
DerOutputStream intStream = new DerOutputStream()) {
// Hash algorithm
hashAlg.derEncodeWithContext(tmp, 0);
// Mask Gen Function Sequence
mgf.putOID(maskGenFunc.getOID());
// MGF hash alg is the same as the hash Alg at this point.
hashAlg.encode(mgf);
seq1.write(DerValue.tag_Sequence, mgf);
tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 1), seq1);
// Salt Length
intStream.putInteger(saltLen);
tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 2), intStream);
// Ignore trailer field, it never changes over all sequence tags
out.write(DerValue.tag_Sequence, tmp);
byte[] data = out.toByteArray();
}
}
Aggregations