Example #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private byte[] encode(ObjectIdentifier type, String[] values) throws java.io.IOException
        private sbyte[] Encode(ObjectIdentifier type, String[] values)
        {
            DerOutputStream attribute = new DerOutputStream();

            attribute.putOID(type);
            DerOutputStream attrContent = new DerOutputStream();

            foreach (String value in values)
            {
                if (COLON_SEPARATED_HEX_PAIRS.Matcher(value).Matches())
                {
                    sbyte[] bytes = (new System.Numerics.BigInteger(value.Replace(":", ""), 16)).ToByteArray();
                    if (bytes[0] == 0)
                    {
                        bytes = Arrays.CopyOfRange(bytes, 1, bytes.Length);
                    }
                    attrContent.putOctetString(bytes);
                }
                else
                {
                    attrContent.putUTF8String(value);
                }
            }
            attribute.write(DerValue.tag_Set, attrContent);
            DerOutputStream attributeValue = new DerOutputStream();

            attributeValue.write(DerValue.tag_Sequence, attribute);

            return(attributeValue.toByteArray());
        }