/** * Parse the given X.509 name into DER encoded byte array representation. * * @param the X.509 name in well known String format * @return the X.509 name as byte array * @exception IOException if the String could not be parsed */ private static byte[] parseX509Name(String data) throws IOException { // TODO more test for illegal charateers ByteArrayOutputStream outStream = new ByteArrayOutputStream(); DEROutputStream derOutStream = new DEROutputStream(outStream); derOutStream.writeObject(new X509Name(trimX509Name(data))); derOutStream.close(); return outStream.toByteArray(); }
/** * Returns the ASN.1 encoding of this object. * * @returns the ASN.1 encoding. * @throws IOException if error occurs when constructing its ASN.1 encoding. */ public byte[] getEncoded() throws IOException { ByteArrayOutputStream bOut = new ByteArrayOutputStream(); DEROutputStream dOut = new DEROutputStream(bOut); dOut.writeObject(infoObj); dOut.close(); return bOut.toByteArray(); }
/** * Parse the given DNS name into DER encoded byte array representation. The String must be in den * preffered name syntax as defined in RFC 1034. * * @param the DNS name in well known String format * @return the DNS name as byte array * @exception IOException if the String could not be parsed */ private static byte[] parseDNSName(String data) throws IOException { // TODO more test for illegal charateers ASN1Object derData = new DERIA5String(data); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); DEROutputStream derOutStream = new DEROutputStream(outStream); derOutStream.writeObject(derData); derOutStream.close(); return outStream.toByteArray(); }
/** * Parse the given URI into DER encoded byte array representation. * * @param the URI in well known String format * @return the URI as byte array * @exception IOException if the String could not be parsed */ private static byte[] parseURI(String data) throws IOException { // TODO do parsing test ASN1Object derData = new DERIA5String(data); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); DEROutputStream derOutStream = new DEROutputStream(outStream); derOutStream.writeObject(derData); derOutStream.close(); return outStream.toByteArray(); }
/** * Parse the given rfc822 addr-spec into DER encoded byte array representation. * * @param the rfc822 addr-spec in well known String format * @return the rfc822 addr-spec as byte array * @exception IOException if the String could not be parsed */ private static byte[] parseRfc822(String data) throws IOException { int tmpInt = data.indexOf('@'); if (tmpInt < 0 || tmpInt >= data.length() - 1) { throw new IOException("wrong format of rfc822Name:" + data); } // TODO more test for illegal charateers ASN1Object derData = new DERIA5String(data); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); DEROutputStream derOutStream = new DEROutputStream(outStream); derOutStream.writeObject(derData); derOutStream.close(); return outStream.toByteArray(); }
private AlgorithmParameters getParameters() throws NoSuchAlgorithmException { AlgorithmParameters ap = AlgorithmParameters.getInstance(this.getAlgName()); ByteArrayOutputStream bOut = new ByteArrayOutputStream(); DEROutputStream dOut = new DEROutputStream(bOut); try { dOut.writeObject(infoObj.getEncryptionAlgorithm().getParameters()); dOut.close(); ap.init(bOut.toByteArray()); } catch (IOException e) { throw new NoSuchAlgorithmException("unable to parse parameters"); } return ap; }
/** * Check the format of an OID.<br> * Throw an IOException if the first component is not 0, 1 or 2 or the second component is greater * than 39.<br> * <br> * User {@link org.bouncycastle.asn1.OIDTokenizer OIDTokenizer} * * @param the OID to be checked. * @exception IOException if the first component is not 0, 1 or 2 or the second component is * greater than 39. */ static byte[] parseOID(String oid) throws IOException { OIDTokenizer tokenizer = new OIDTokenizer(oid); String token; if (!tokenizer.hasMoreTokens()) { throw new IOException("OID contains no tokens"); } token = tokenizer.nextToken(); if (token == null) { throw new IOException("OID contains no tokens"); } try { int test = (Integer.valueOf(token)).intValue(); if (test < 0 || test > 2) { throw new IOException("first token is not >= 0 and <=2"); } if (!tokenizer.hasMoreTokens()) { throw new IOException("OID contains only one token"); } token = tokenizer.nextToken(); if (token == null) { throw new IOException("OID contains only one token"); } test = (Integer.valueOf(token)).intValue(); if (test < 0 || test > 39) { throw new IOException("secon token is not >= 0 and <=39"); } } catch (NumberFormatException ex) { throw new IOException("token: " + token + ": " + ex.toString()); } ASN1Object derData = new ASN1ObjectIdentifier(oid); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); DEROutputStream derOutStream = new DEROutputStream(outStream); derOutStream.writeObject(derData); derOutStream.close(); return outStream.toByteArray(); }