use of org.mozilla.jss.asn1.ASN1Template in project jss by dogtagpki.
the class JSSUtil method decode.
public static String decode(byte tag, byte[] bytes) throws Exception {
ASN1Template template;
switch(tag) {
case DerValue.tag_BMPString:
template = new BMPString.Template();
break;
case DerValue.tag_IA5String:
template = new IA5String.Template();
break;
case DerValue.tag_PrintableString:
template = new PrintableString.Template();
break;
case DerValue.tag_T61String:
template = new TeletexString.Template();
break;
case DerValue.tag_UniversalString:
template = new UniversalString.Template();
break;
case DerValue.tag_UTF8String:
template = new UTF8String.Template();
break;
default:
throw new Exception("Unsupported tag: " + tag);
}
ASN1Value asnValue = ASN1Util.decode(new Tag(Tag.UNIVERSAL, tag), template, bytes);
if (asnValue == null) {
throw new Exception("Cannot decode the given bytes.");
}
return asnValue.toString();
}
Aggregations