Java tutorial
//package com.java2s; import java.util.regex.*; public class Main { /** * Verifies that an OID is in dot-separated string format. * TODO: Make this more robust. * * @param oid OID to verify * @return true if OID is valid, false otherwise */ public static boolean verifyOid(String oid) { // Pattern to match '.' separated Oid string format Pattern oidPattern = Pattern.compile("^([0-9]+.{1})+[0-9]+$"); Matcher oidIN = oidPattern.matcher(oid); if (oidIN.matches()) { return true; } else { return false; } } /** * Verifies DER-encoded byte array has a valid tag and length * * @param oid OID to verify, DER-encoded byte array * @return true if OID is valid, false otherwise */ public static boolean verifyOid(byte[] oid) { /* verify tag is set to an OID (0x06) */ if (oid[0] != 6) return false; /* verify length is correct */ if (oid.length - 2 != oid[1]) { return false; } return true; } }