Java Code Examples for sun.security.pkcs.PKCS9Attribute#derEncode()

The following examples show how to use sun.security.pkcs.PKCS9Attribute#derEncode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UnknownAttribute.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Unknown attr
    PKCS9Attribute p1 = new PKCS9Attribute(
            PKCS9Attribute.CHALLENGE_PASSWORD_STR, "t0p5ecr3t");
    if (!p1.isKnown()) {
        throw new Exception();
    }
    // Unknown attr from DER
    byte[] data = {
            0x30, 0x08,                 // SEQUENCE OF
            0x06, 0x02, 0x2A, 0x03,     // OID 1.2.3 and
            0x31, 0x02, 0x05, 0x00      // an empty SET
    };
    PKCS9Attribute p2 = new PKCS9Attribute(new DerValue(data));
    if (p2.isKnown()) {
        throw new Exception();
    }
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    p2.derEncode(bout);
    new HexDumpEncoder().encodeBuffer(bout.toByteArray(), System.err);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
    // Unknown attr from value
    try {
        new PKCS9Attribute(new ObjectIdentifier("1.2.3"), "hello");
        throw new Exception();
    } catch (IllegalArgumentException iae) {
        // Good. Unknown attr must have byte[] value type
    }
    PKCS9Attribute p3 = new PKCS9Attribute(
            new ObjectIdentifier("1.2.3"), new byte[]{0x31,0x02,0x05,0x00});
    if (p3.isKnown()) {
        throw new Exception();
    }
    bout = new ByteArrayOutputStream();
    p3.derEncode(bout);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
}
 
Example 2
Source File: UnknownAttribute.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Unknown attr
    PKCS9Attribute p1 = new PKCS9Attribute(
            PKCS9Attribute.CHALLENGE_PASSWORD_STR, "t0p5ecr3t");
    if (!p1.isKnown()) {
        throw new Exception();
    }
    // Unknown attr from DER
    byte[] data = {
            0x30, 0x08,                 // SEQUENCE OF
            0x06, 0x02, 0x2A, 0x03,     // OID 1.2.3 and
            0x31, 0x02, 0x05, 0x00      // an empty SET
    };
    PKCS9Attribute p2 = new PKCS9Attribute(new DerValue(data));
    if (p2.isKnown()) {
        throw new Exception();
    }
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    p2.derEncode(bout);
    new HexDumpEncoder().encodeBuffer(bout.toByteArray(), System.err);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
    // Unknown attr from value
    try {
        new PKCS9Attribute(new ObjectIdentifier("1.2.3"), "hello");
        throw new Exception();
    } catch (IllegalArgumentException iae) {
        // Good. Unknown attr must have byte[] value type
    }
    PKCS9Attribute p3 = new PKCS9Attribute(
            new ObjectIdentifier("1.2.3"), new byte[]{0x31,0x02,0x05,0x00});
    if (p3.isKnown()) {
        throw new Exception();
    }
    bout = new ByteArrayOutputStream();
    p3.derEncode(bout);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
}
 
Example 3
Source File: UnknownAttribute.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Unknown attr
    PKCS9Attribute p1 = new PKCS9Attribute(
            PKCS9Attribute.CHALLENGE_PASSWORD_STR, "t0p5ecr3t");
    if (!p1.isKnown()) {
        throw new Exception();
    }
    // Unknown attr from DER
    byte[] data = {
            0x30, 0x08,                 // SEQUENCE OF
            0x06, 0x02, 0x2A, 0x03,     // OID 1.2.3 and
            0x31, 0x02, 0x05, 0x00      // an empty SET
    };
    PKCS9Attribute p2 = new PKCS9Attribute(new DerValue(data));
    if (p2.isKnown()) {
        throw new Exception();
    }
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    p2.derEncode(bout);
    new HexDumpEncoder().encodeBuffer(bout.toByteArray(), System.err);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
    // Unknown attr from value
    try {
        new PKCS9Attribute(new ObjectIdentifier("1.2.3"), "hello");
        throw new Exception();
    } catch (IllegalArgumentException iae) {
        // Good. Unknown attr must have byte[] value type
    }
    PKCS9Attribute p3 = new PKCS9Attribute(
            new ObjectIdentifier("1.2.3"), new byte[]{0x31,0x02,0x05,0x00});
    if (p3.isKnown()) {
        throw new Exception();
    }
    bout = new ByteArrayOutputStream();
    p3.derEncode(bout);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
}
 
Example 4
Source File: UnknownAttribute.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Unknown attr
    PKCS9Attribute p1 = new PKCS9Attribute(
            PKCS9Attribute.CHALLENGE_PASSWORD_STR, "t0p5ecr3t");
    if (!p1.isKnown()) {
        throw new Exception();
    }
    // Unknown attr from DER
    byte[] data = {
            0x30, 0x08,                 // SEQUENCE OF
            0x06, 0x02, 0x2A, 0x03,     // OID 1.2.3 and
            0x31, 0x02, 0x05, 0x00      // an empty SET
    };
    PKCS9Attribute p2 = new PKCS9Attribute(new DerValue(data));
    if (p2.isKnown()) {
        throw new Exception();
    }
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    p2.derEncode(bout);
    new HexDumpEncoder().encodeBuffer(bout.toByteArray(), System.err);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
    // Unknown attr from value
    try {
        new PKCS9Attribute(new ObjectIdentifier("1.2.3"), "hello");
        throw new Exception();
    } catch (IllegalArgumentException iae) {
        // Good. Unknown attr must have byte[] value type
    }
    PKCS9Attribute p3 = new PKCS9Attribute(
            new ObjectIdentifier("1.2.3"), new byte[]{0x31,0x02,0x05,0x00});
    if (p3.isKnown()) {
        throw new Exception();
    }
    bout = new ByteArrayOutputStream();
    p3.derEncode(bout);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
}
 
Example 5
Source File: UnknownAttribute.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Unknown attr
    PKCS9Attribute p1 = new PKCS9Attribute(
            PKCS9Attribute.CHALLENGE_PASSWORD_STR, "t0p5ecr3t");
    if (!p1.isKnown()) {
        throw new Exception();
    }
    // Unknown attr from DER
    byte[] data = {
            0x30, 0x08,                 // SEQUENCE OF
            0x06, 0x02, 0x2A, 0x03,     // OID 1.2.3 and
            0x31, 0x02, 0x05, 0x00      // an empty SET
    };
    PKCS9Attribute p2 = new PKCS9Attribute(new DerValue(data));
    if (p2.isKnown()) {
        throw new Exception();
    }
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    p2.derEncode(bout);
    new HexDumpEncoder().encodeBuffer(bout.toByteArray(), System.err);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
    // Unknown attr from value
    try {
        new PKCS9Attribute(new ObjectIdentifier("1.2.3"), "hello");
        throw new Exception();
    } catch (IllegalArgumentException iae) {
        // Good. Unknown attr must have byte[] value type
    }
    PKCS9Attribute p3 = new PKCS9Attribute(
            new ObjectIdentifier("1.2.3"), new byte[]{0x31,0x02,0x05,0x00});
    if (p3.isKnown()) {
        throw new Exception();
    }
    bout = new ByteArrayOutputStream();
    p3.derEncode(bout);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
}
 
Example 6
Source File: UnknownAttribute.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Unknown attr
    PKCS9Attribute p1 = new PKCS9Attribute(
            PKCS9Attribute.CHALLENGE_PASSWORD_STR, "t0p5ecr3t");
    if (!p1.isKnown()) {
        throw new Exception();
    }
    // Unknown attr from DER
    byte[] data = {
            0x30, 0x08,                 // SEQUENCE OF
            0x06, 0x02, 0x2A, 0x03,     // OID 1.2.3 and
            0x31, 0x02, 0x05, 0x00      // an empty SET
    };
    PKCS9Attribute p2 = new PKCS9Attribute(new DerValue(data));
    if (p2.isKnown()) {
        throw new Exception();
    }
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    p2.derEncode(bout);
    new HexDumpEncoder().encodeBuffer(bout.toByteArray(), System.err);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
    // Unknown attr from value
    try {
        new PKCS9Attribute(new ObjectIdentifier("1.2.3"), "hello");
        throw new Exception();
    } catch (IllegalArgumentException iae) {
        // Good. Unknown attr must have byte[] value type
    }
    PKCS9Attribute p3 = new PKCS9Attribute(
            new ObjectIdentifier("1.2.3"), new byte[]{0x31,0x02,0x05,0x00});
    if (p3.isKnown()) {
        throw new Exception();
    }
    bout = new ByteArrayOutputStream();
    p3.derEncode(bout);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
}
 
Example 7
Source File: UnknownAttribute.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Unknown attr
    PKCS9Attribute p1 = new PKCS9Attribute(
            PKCS9Attribute.CHALLENGE_PASSWORD_STR, "t0p5ecr3t");
    if (!p1.isKnown()) {
        throw new Exception();
    }
    // Unknown attr from DER
    byte[] data = {
            0x30, 0x08,                 // SEQUENCE OF
            0x06, 0x02, 0x2A, 0x03,     // OID 1.2.3 and
            0x31, 0x02, 0x05, 0x00      // an empty SET
    };
    PKCS9Attribute p2 = new PKCS9Attribute(new DerValue(data));
    if (p2.isKnown()) {
        throw new Exception();
    }
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    p2.derEncode(bout);
    new HexDumpEncoder().encodeBuffer(bout.toByteArray(), System.err);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
    // Unknown attr from value
    try {
        new PKCS9Attribute(new ObjectIdentifier("1.2.3"), "hello");
        throw new Exception();
    } catch (IllegalArgumentException iae) {
        // Good. Unknown attr must have byte[] value type
    }
    PKCS9Attribute p3 = new PKCS9Attribute(
            new ObjectIdentifier("1.2.3"), new byte[]{0x31,0x02,0x05,0x00});
    if (p3.isKnown()) {
        throw new Exception();
    }
    bout = new ByteArrayOutputStream();
    p3.derEncode(bout);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
}
 
Example 8
Source File: UnknownAttribute.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Unknown attr
    PKCS9Attribute p1 = new PKCS9Attribute(
            PKCS9Attribute.CHALLENGE_PASSWORD_STR, "t0p5ecr3t");
    if (!p1.isKnown()) {
        throw new Exception();
    }
    // Unknown attr from DER
    byte[] data = {
            0x30, 0x08,                 // SEQUENCE OF
            0x06, 0x02, 0x2A, 0x03,     // OID 1.2.3 and
            0x31, 0x02, 0x05, 0x00      // an empty SET
    };
    PKCS9Attribute p2 = new PKCS9Attribute(new DerValue(data));
    if (p2.isKnown()) {
        throw new Exception();
    }
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    p2.derEncode(bout);
    new HexDumpEncoder().encodeBuffer(bout.toByteArray(), System.err);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
    // Unknown attr from value
    try {
        new PKCS9Attribute(new ObjectIdentifier("1.2.3"), "hello");
        throw new Exception();
    } catch (IllegalArgumentException iae) {
        // Good. Unknown attr must have byte[] value type
    }
    PKCS9Attribute p3 = new PKCS9Attribute(
            new ObjectIdentifier("1.2.3"), new byte[]{0x31,0x02,0x05,0x00});
    if (p3.isKnown()) {
        throw new Exception();
    }
    bout = new ByteArrayOutputStream();
    p3.derEncode(bout);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
}
 
Example 9
Source File: UnknownAttribute.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Unknown attr
    PKCS9Attribute p1 = new PKCS9Attribute(
            PKCS9Attribute.CHALLENGE_PASSWORD_STR, "t0p5ecr3t");
    if (!p1.isKnown()) {
        throw new Exception();
    }
    // Unknown attr from DER
    byte[] data = {
            0x30, 0x08,                 // SEQUENCE OF
            0x06, 0x02, 0x2A, 0x03,     // OID 1.2.3 and
            0x31, 0x02, 0x05, 0x00      // an empty SET
    };
    PKCS9Attribute p2 = new PKCS9Attribute(new DerValue(data));
    if (p2.isKnown()) {
        throw new Exception();
    }
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    p2.derEncode(bout);
    new HexDumpEncoder().encodeBuffer(bout.toByteArray(), System.err);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
    // Unknown attr from value
    try {
        new PKCS9Attribute(new ObjectIdentifier("1.2.3"), "hello");
        throw new Exception();
    } catch (IllegalArgumentException iae) {
        // Good. Unknown attr must have byte[] value type
    }
    PKCS9Attribute p3 = new PKCS9Attribute(
            new ObjectIdentifier("1.2.3"), new byte[]{0x31,0x02,0x05,0x00});
    if (p3.isKnown()) {
        throw new Exception();
    }
    bout = new ByteArrayOutputStream();
    p3.derEncode(bout);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
}
 
Example 10
Source File: PKCS10Attribute.java    From jdk8u_jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * DER encode this object onto an output stream.
 * Implements the <code>DerEncoder</code> interface.
 *
 * @param out
 * the OutputStream on which to write the DER encoding.
 *
 * @exception IOException on encoding errors.
 */
public void derEncode(OutputStream out) throws IOException {
    PKCS9Attribute attr = new PKCS9Attribute(attributeId, attributeValue);
    attr.derEncode(out);
}
 
Example 11
Source File: PKCS10Attribute.java    From openjdk-8-source with GNU General Public License v2.0 2 votes vote down vote up
/**
 * DER encode this object onto an output stream.
 * Implements the <code>DerEncoder</code> interface.
 *
 * @param out
 * the OutputStream on which to write the DER encoding.
 *
 * @exception IOException on encoding errors.
 */
public void derEncode(OutputStream out) throws IOException {
    PKCS9Attribute attr = new PKCS9Attribute(attributeId, attributeValue);
    attr.derEncode(out);
}
 
Example 12
Source File: PKCS10Attribute.java    From jdk8u-dev-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * DER encode this object onto an output stream.
 * Implements the <code>DerEncoder</code> interface.
 *
 * @param out
 * the OutputStream on which to write the DER encoding.
 *
 * @exception IOException on encoding errors.
 */
public void derEncode(OutputStream out) throws IOException {
    PKCS9Attribute attr = new PKCS9Attribute(attributeId, attributeValue);
    attr.derEncode(out);
}
 
Example 13
Source File: PKCS10Attribute.java    From hottub with GNU General Public License v2.0 2 votes vote down vote up
/**
 * DER encode this object onto an output stream.
 * Implements the <code>DerEncoder</code> interface.
 *
 * @param out
 * the OutputStream on which to write the DER encoding.
 *
 * @exception IOException on encoding errors.
 */
public void derEncode(OutputStream out) throws IOException {
    PKCS9Attribute attr = new PKCS9Attribute(attributeId, attributeValue);
    attr.derEncode(out);
}
 
Example 14
Source File: PKCS10Attribute.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * DER encode this object onto an output stream.
 * Implements the <code>DerEncoder</code> interface.
 *
 * @param out
 * the OutputStream on which to write the DER encoding.
 *
 * @exception IOException on encoding errors.
 */
public void derEncode(OutputStream out) throws IOException {
    PKCS9Attribute attr = new PKCS9Attribute(attributeId, attributeValue);
    attr.derEncode(out);
}
 
Example 15
Source File: PKCS10Attribute.java    From Bytecoder with Apache License 2.0 2 votes vote down vote up
/**
 * DER encode this object onto an output stream.
 * Implements the <code>DerEncoder</code> interface.
 *
 * @param out
 * the OutputStream on which to write the DER encoding.
 *
 * @exception IOException on encoding errors.
 */
public void derEncode(OutputStream out) throws IOException {
    PKCS9Attribute attr = new PKCS9Attribute(attributeId, attributeValue);
    attr.derEncode(out);
}
 
Example 16
Source File: PKCS10Attribute.java    From jdk8u-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * DER encode this object onto an output stream.
 * Implements the <code>DerEncoder</code> interface.
 *
 * @param out
 * the OutputStream on which to write the DER encoding.
 *
 * @exception IOException on encoding errors.
 */
public void derEncode(OutputStream out) throws IOException {
    PKCS9Attribute attr = new PKCS9Attribute(attributeId, attributeValue);
    attr.derEncode(out);
}
 
Example 17
Source File: PKCS10Attribute.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 2 votes vote down vote up
/**
 * DER encode this object onto an output stream.
 * Implements the <code>DerEncoder</code> interface.
 *
 * @param out
 * the OutputStream on which to write the DER encoding.
 *
 * @exception IOException on encoding errors.
 */
public void derEncode(OutputStream out) throws IOException {
    PKCS9Attribute attr = new PKCS9Attribute(attributeId, attributeValue);
    attr.derEncode(out);
}
 
Example 18
Source File: PKCS10Attribute.java    From openjdk-jdk8u with GNU General Public License v2.0 2 votes vote down vote up
/**
 * DER encode this object onto an output stream.
 * Implements the <code>DerEncoder</code> interface.
 *
 * @param out
 * the OutputStream on which to write the DER encoding.
 *
 * @exception IOException on encoding errors.
 */
public void derEncode(OutputStream out) throws IOException {
    PKCS9Attribute attr = new PKCS9Attribute(attributeId, attributeValue);
    attr.derEncode(out);
}
 
Example 19
Source File: PKCS10Attribute.java    From jdk8u60 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * DER encode this object onto an output stream.
 * Implements the <code>DerEncoder</code> interface.
 *
 * @param out
 * the OutputStream on which to write the DER encoding.
 *
 * @exception IOException on encoding errors.
 */
public void derEncode(OutputStream out) throws IOException {
    PKCS9Attribute attr = new PKCS9Attribute(attributeId, attributeValue);
    attr.derEncode(out);
}
 
Example 20
Source File: PKCS10Attribute.java    From TencentKona-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * DER encode this object onto an output stream.
 * Implements the <code>DerEncoder</code> interface.
 *
 * @param out
 * the OutputStream on which to write the DER encoding.
 *
 * @exception IOException on encoding errors.
 */
public void derEncode(OutputStream out) throws IOException {
    PKCS9Attribute attr = new PKCS9Attribute(attributeId, attributeValue);
    attr.derEncode(out);
}