Search in sources :

Example 1 with DerValue

use of org.mozilla.jss.netscape.security.util.DerValue 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 DerValue

use of org.mozilla.jss.netscape.security.util.DerValue in project jss by dogtagpki.

the class StringTestUtil method normalizeUnicode.

public static byte[] normalizeUnicode(byte[] data) throws Exception {
    try (DerOutputStream os = new DerOutputStream()) {
        DerValue value = new DerValue(data);
        byte[] tmp = value.data.toByteArray();
        if (tmp[0] == -2 && tmp[1] == -1) {
            // remove optional big-endian byte-order mark
            byte tag = value.tag;
            int length = value.length() - 2;
            os.putTag((byte) 0, false, tag);
            os.putLength(length);
            os.write(tmp, 2, length);
            return os.toByteArray();
        }
        return data;
    }
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream) DerValue(org.mozilla.jss.netscape.security.util.DerValue)

Example 3 with DerValue

use of org.mozilla.jss.netscape.security.util.DerValue in project jss by dogtagpki.

the class EmptyDerValue method main.

public static void main(String[] args) throws Exception {
    byte[] bytes = { 0x04, 0x00 };
    DerValue derVal = new DerValue(bytes);
    System.out.println(derVal.getOctetString());
}
Also used : DerValue(org.mozilla.jss.netscape.security.util.DerValue)

Example 4 with DerValue

use of org.mozilla.jss.netscape.security.util.DerValue in project jss by dogtagpki.

the class EnumerationZeroTest method outputExtension.

/**
 * Output the DER encoding of a CRLExtension for examination
 */
public static void outputExtension(CRLReasonExtension ext) throws Exception {
    ByteArrayOutputStream resultBytesOut = new ByteArrayOutputStream();
    ext.encode(resultBytesOut);
    byte[] encodedBytes = resultBytesOut.toByteArray();
    System.out.print("Full encoded extension: " + toHex(encodedBytes));
    Extension reasonExt = new Extension(new DerValue(encodedBytes));
    System.out.print("\tEncoded CRL Reason: " + toHex(reasonExt.getExtensionValue()));
    DerValue reasonValue = new DerValue(reasonExt.getExtensionValue());
    System.out.println("\tReason value: " + reasonValue.getEnumerated());
}
Also used : AuthorityKeyIdentifierExtension(org.mozilla.jss.netscape.security.x509.AuthorityKeyIdentifierExtension) CRLNumberExtension(org.mozilla.jss.netscape.security.x509.CRLNumberExtension) CRLReasonExtension(org.mozilla.jss.netscape.security.x509.CRLReasonExtension) Extension(org.mozilla.jss.netscape.security.x509.Extension) DerValue(org.mozilla.jss.netscape.security.util.DerValue) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 5 with DerValue

use of org.mozilla.jss.netscape.security.util.DerValue in project jss by dogtagpki.

the class X509CertImpl method decode.

/**
 * Decode an X.509 certificate from an input stream.
 *
 * @param in an input stream holding at least one certificate
 * @exception CertificateException on parsing errors.
 * @exception IOException on other errors.
 */
public void decode(InputStream in) throws CertificateException, IOException {
    DerValue val = new DerValue(in);
    parse(val);
    signedCert = val.toByteArray();
}
Also used : DerValue(org.mozilla.jss.netscape.security.util.DerValue)

Aggregations

DerValue (org.mozilla.jss.netscape.security.util.DerValue)70 IOException (java.io.IOException)31 DerInputStream (org.mozilla.jss.netscape.security.util.DerInputStream)20 DerOutputStream (org.mozilla.jss.netscape.security.util.DerOutputStream)8 ObjectIdentifier (org.mozilla.jss.netscape.security.util.ObjectIdentifier)8 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 ByteBuffer (java.nio.ByteBuffer)4 CharBuffer (java.nio.CharBuffer)4 CharacterCodingException (java.nio.charset.CharacterCodingException)4 CharsetEncoder (java.nio.charset.CharsetEncoder)4 MessageDigest (java.security.MessageDigest)4 CRLException (java.security.cert.CRLException)4 BitArray (org.mozilla.jss.netscape.security.util.BitArray)4 AuthorityKeyIdentifierExtension (org.mozilla.jss.netscape.security.x509.AuthorityKeyIdentifierExtension)4 KeyIdentifier (org.mozilla.jss.netscape.security.x509.KeyIdentifier)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 InvalidKeyException (java.security.InvalidKeyException)3 BigInt (org.mozilla.jss.netscape.security.util.BigInt)3 GeneralName (org.mozilla.jss.netscape.security.x509.GeneralName)3 CertificateException (java.security.cert.CertificateException)2