use of org.mozilla.jss.netscape.security.util.BigInt in project jss by dogtagpki.
the class X509CertTest method convertPublicKeyToX509Key.
public static X509Key convertPublicKeyToX509Key(PublicKey pubk) throws Exception {
X509Key xKey = null;
if (pubk instanceof RSAPublicKey) {
RSAPublicKey rsaKey = (RSAPublicKey) pubk;
xKey = new org.mozilla.jss.netscape.security.provider.RSAPublicKey(new BigInt(rsaKey.getModulus()), new BigInt(rsaKey.getPublicExponent()));
} else if (pubk instanceof PK11ECPublicKey) {
byte[] encoded = pubk.getEncoded();
xKey = X509Key.parse(new DerValue(encoded));
}
return xKey;
}
use of org.mozilla.jss.netscape.security.util.BigInt in project jss by dogtagpki.
the class X509CRLImpl method encodeInfo.
/**
* Encodes the "to-be-signed" CRL to the OutputStream.
*
* @param out the OutputStream to write to.
* @exception CRLException on encoding errors.
* @exception X509ExtensionException on extension encoding errors.
*/
public void encodeInfo(OutputStream out) throws CRLException, X509ExtensionException {
try (DerOutputStream seq = new DerOutputStream()) {
DerOutputStream tmp = new DerOutputStream();
DerOutputStream rCerts = new DerOutputStream();
if (// v2 crl encode version
version != 0)
tmp.putInteger(new BigInt(version));
infoSigAlgId.encode(tmp);
issuer.encode(tmp);
// from 2050 should encode GeneralizedTime
tmp.putUTCTime(thisUpdate);
if (nextUpdate != null)
tmp.putUTCTime(nextUpdate);
if (!revokedCerts.isEmpty()) {
for (Enumeration<RevokedCertificate> e = revokedCerts.elements(); e.hasMoreElements(); ) ((RevokedCertImpl) e.nextElement()).encode(rCerts);
tmp.write(DerValue.tag_Sequence, rCerts);
}
if (extensions != null)
extensions.encode(tmp, isExplicit);
seq.write(DerValue.tag_Sequence, tmp);
tbsCertList = seq.toByteArray();
out.write(tbsCertList);
} catch (IOException e) {
throw new CRLException("Encoding error: " + e.getMessage());
}
}
use of org.mozilla.jss.netscape.security.util.BigInt in project jss by dogtagpki.
the class PKCS8Key method encode.
/*
* Produce PKCS#8 encoding from algorithm id and key material.
*/
static void encode(DerOutputStream out, AlgorithmId algid, byte[] key) throws IOException {
DerOutputStream tmp = new DerOutputStream();
tmp.putInteger(new BigInt(VERSION.toByteArray()));
algid.encode(tmp);
tmp.putOctetString(key);
out.write(DerValue.tag_Sequence, tmp);
}
use of org.mozilla.jss.netscape.security.util.BigInt in project jss by dogtagpki.
the class AlgIdDSA method initializeParams.
/*
* For algorithm IDs which haven't been created from a DER encoded
* value, "params" must be created.
*/
private void initializeParams() throws IOException {
try (DerOutputStream out = new DerOutputStream()) {
out.putInteger(new BigInt(p.toByteArray()));
out.putInteger(new BigInt(q.toByteArray()));
out.putInteger(new BigInt(g.toByteArray()));
params = new DerValue(DerValue.tag_Sequence, out.toByteArray());
}
}
use of org.mozilla.jss.netscape.security.util.BigInt in project jss by dogtagpki.
the class KerberosName method encode.
/**
* Write the extension to the DerOutputStream.
*
* @param out the DerOutputStream to write the extension to.
* @exception IOException on encoding errors.
*/
public void encode(OutputStream out) throws IOException {
try (DerOutputStream seq = new DerOutputStream()) {
DerOutputStream tmp = new DerOutputStream();
DerOutputStream realm = new DerOutputStream();
realm.putGeneralString(m_realm);
tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0), realm);
DerOutputStream seq1 = new DerOutputStream();
DerOutputStream tmp1 = new DerOutputStream();
DerOutputStream name_type = new DerOutputStream();
name_type.putInteger(new BigInt(m_name_type));
tmp1.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0), name_type);
DerOutputStream name_strings = new DerOutputStream();
DerOutputStream name_string = new DerOutputStream();
for (int i = 0; i < m_name_strings.size(); i++) {
name_string.putGeneralString(m_name_strings.elementAt(i));
}
name_strings.write(DerValue.tag_SequenceOf, name_string);
tmp1.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 1), name_strings);
seq1.write(DerValue.tag_Sequence, tmp1);
tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 1), seq1);
seq.write(DerValue.tag_Sequence, tmp);
out.write(seq.toByteArray());
}
}
Aggregations