Search in sources :

Example 1 with BigInt

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;
}
Also used : PK11ECPublicKey(org.mozilla.jss.pkcs11.PK11ECPublicKey) RSAPublicKey(java.security.interfaces.RSAPublicKey) DerValue(org.mozilla.jss.netscape.security.util.DerValue) BigInt(org.mozilla.jss.netscape.security.util.BigInt) X509Key(org.mozilla.jss.netscape.security.x509.X509Key) CertificateX509Key(org.mozilla.jss.netscape.security.x509.CertificateX509Key)

Example 2 with BigInt

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());
    }
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream) BigInt(org.mozilla.jss.netscape.security.util.BigInt) IOException(java.io.IOException) CRLException(java.security.cert.CRLException)

Example 3 with BigInt

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);
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream) BigInt(org.mozilla.jss.netscape.security.util.BigInt)

Example 4 with BigInt

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());
    }
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream) DerValue(org.mozilla.jss.netscape.security.util.DerValue) BigInt(org.mozilla.jss.netscape.security.util.BigInt)

Example 5 with BigInt

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());
    }
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream) BigInt(org.mozilla.jss.netscape.security.util.BigInt)

Aggregations

BigInt (org.mozilla.jss.netscape.security.util.BigInt)17 DerOutputStream (org.mozilla.jss.netscape.security.util.DerOutputStream)13 DerValue (org.mozilla.jss.netscape.security.util.DerValue)3 IOException (java.io.IOException)2 AlgorithmId (org.mozilla.jss.netscape.security.x509.AlgorithmId)2 BigInteger (java.math.BigInteger)1 SignatureException (java.security.SignatureException)1 CRLException (java.security.cert.CRLException)1 X509Certificate (java.security.cert.X509Certificate)1 RSAPublicKey (java.security.interfaces.RSAPublicKey)1 MGF1ParameterSpec (java.security.spec.MGF1ParameterSpec)1 PSSParameterSpec (java.security.spec.PSSParameterSpec)1 DerInputStream (org.mozilla.jss.netscape.security.util.DerInputStream)1 ObjectIdentifier (org.mozilla.jss.netscape.security.util.ObjectIdentifier)1 CertificateX509Key (org.mozilla.jss.netscape.security.x509.CertificateX509Key)1 X500Name (org.mozilla.jss.netscape.security.x509.X500Name)1 X509Key (org.mozilla.jss.netscape.security.x509.X509Key)1 PK11ECPublicKey (org.mozilla.jss.pkcs11.PK11ECPublicKey)1