Search in sources :

Example 1 with PrintableString

use of org.mozilla.jss.asn1.PrintableString in project jss by dogtagpki.

the class Name method main.

public static void main(String[] args) {
    try {
        if (args.length == 0) {
            Name name = new Name();
            OBJECT_IDENTIFIER oid;
            oid = new OBJECT_IDENTIFIER(new long[] { 2, 5, 4, 10 });
            AVA ava = new AVA(oid, new PrintableString("Netscape"));
            name.addElement(ava);
            oid = new OBJECT_IDENTIFIER(new long[] { 2, 5, 4, 3 });
            ava = new AVA(oid, new PrintableString("moi"));
            name.addElement(ava);
            name.encode(System.out);
        } else {
            Name.Template temp = new Name.Template();
            Name name;
            FileInputStream fis = new FileInputStream(args[0]);
            try (BufferedInputStream bis = new BufferedInputStream(fis)) {
                name = (Name) temp.decode(bis);
            }
            System.out.println("Got name.");
            for (int i = 0; i < name.size(); i++) {
                AVA a = name.elementAt(i).at(0);
                PrintableString.Template pst = new PrintableString.Template();
                PrintableString ps = (PrintableString) pst.decode(new ByteArrayInputStream(a.getValue().getEncoded()));
                System.out.println("OID: " + a.getOID() + ", String: " + ps);
            }
            System.out.println("End of name");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : PrintableString(org.mozilla.jss.asn1.PrintableString) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) OBJECT_IDENTIFIER(org.mozilla.jss.asn1.OBJECT_IDENTIFIER) FileInputStream(java.io.FileInputStream) InvalidBERException(org.mozilla.jss.asn1.InvalidBERException) IOException(java.io.IOException) CharConversionException(java.io.CharConversionException) ASN1Template(org.mozilla.jss.asn1.ASN1Template)

Aggregations

BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 CharConversionException (java.io.CharConversionException)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 ASN1Template (org.mozilla.jss.asn1.ASN1Template)1 InvalidBERException (org.mozilla.jss.asn1.InvalidBERException)1 OBJECT_IDENTIFIER (org.mozilla.jss.asn1.OBJECT_IDENTIFIER)1 PrintableString (org.mozilla.jss.asn1.PrintableString)1