}
static public Token decryptToken(byte[] productionKey, byte[] encryptedToken) throws Exception {
try {
BerObject outerObj = BerDecoder.decode(encryptedToken);
if( false == outerObj.isTypeConstructed()
|| false == (outerObj instanceof BerConstructed) ){
throw new Exception("Object is not constructed.");
}
if( Token.APPLICATION_TYPE_ENCRYPTED != outerObj.getType() ){
throw new Exception("Unexpected type.");
}
BerConstructed outer = (BerConstructed)outerObj;
// Check that we have enough members
if( outer.size() < 2 ){
throw new Exception("Not enough components.");
}
// Get context
BerObject contextObj = outer.get(0);
if( false == (contextObj instanceof BerBytes) ){
throw new Exception("Invalid context.");
}
byte[] context = ((BerBytes)contextObj).getValue();
// Get encrypted payload
BerObject encryptedObj = outer.get(1);
if( false == (encryptedObj instanceof BerBytes) ){
throw new Exception("Invalid encrypted payload.");
}
byte[] encryptedPayload = ((BerBytes)encryptedObj).getValue();