/**
   * Method decode.
   *
   * @param ba byte[]
   */
  public void decode(byte[] ba) {

    Enumeration<TLV> tlvs = BERTLVFactory.decodeTLV(ba);
    while (tlvs.hasMoreElements()) {
      TLV current_tlv = tlvs.nextElement();

      Enumeration<TLV> children = BERTLVFactory.decodeTLV(current_tlv.getValue());
      while (children.hasMoreElements()) {

        TLV child_tlv = children.nextElement();
        Tag child_tag = child_tlv.getTag();
        byte[] value = child_tlv.getValue();

        switch (child_tag.getBytes()[0]) {
          case Tag.AK_ALGORITHM_ID:
            {
              this.algorithmID = value[0];
              break;
            }
          case Tag.AK_PARAMETER:
            {
              this.parameter = value;
              break;
            }
          default:
            {
              break;
            }
        }
      }
    }
  }
Exemplo n.º 2
0
  /**
   * Method decode.
   *
   * @param ba byte[]
   */
  private void decode(byte[] ba) {

    Enumeration<?> children = BERTLVFactory.decodeTLV(ba);
    while (children.hasMoreElements()) {

      TLV child_tlv = (TLV) children.nextElement();
      Tag child_tag = child_tlv.getTag();
      byte[] value = child_tlv.getValue();

      switch (child_tag.getBytes()[0]) {
        case Tag.CHUID_FASCN:
          {
            this.fascn = value;
            break;
          }
        case Tag.CHUID_AGENCY_CODE:
          {
            this.ac = value;
            break;
          }
        case Tag.CHUID_ORG_ID:
          {
            this.oi = value;
            break;
          }
        case Tag.CHUID_DUNS:
          {
            this.duns = value;
            break;
          }
        case Tag.CHUID_GUID:
          {
            this.guid = value;
            break;
          }
        case Tag.CHUID_EXPIRATION_DATE:
          {
            this.expires = value;
            break;
          }
        case Tag.CHUID_SIGNATURE:
          {
            this.signature = value;
            break;
          }
        case Tag.CHUID_ERROR_DETECT_CODE:
          {
            this.edc = value;
            break;
          }
        default:
          {
            break;
          }
      }
    }
  }
Exemplo n.º 3
0
  /**
   * Method getSignatureDataBytes.
   *
   * @return byte[]
   */
  public byte[] getSignatureDataBytes() {

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    try {

      if (debug) {
        System.out.println("Decodeing CHUID Signature Data");
      }

      Enumeration<?> children = BERTLVFactory.decodeTLV(this.chuid);
      while (children.hasMoreElements()) {

        TLV child_tlv = (TLV) children.nextElement();
        Tag child_tag = child_tlv.getTag();
        // byte[] value = child_tlv.getValue();

        switch (child_tag.getBytes()[0]) {
          case Tag.CHUID_FASCN:
            {
              baos.write(child_tlv.getBytes());
              if (debug) {
                System.out.println("Decoded CHUID_FASCN.");
              }
              break;
            }
          case Tag.CHUID_AGENCY_CODE:
            {
              baos.write(child_tlv.getBytes());
              if (debug) {
                System.out.println("Decoded CHUID_AGENCY_CODE.");
              }
              break;
            }
          case Tag.CHUID_ORG_ID:
            {
              baos.write(child_tlv.getBytes());
              if (debug) {
                System.out.println("Decoded CHUID_ORG_ID.");
              }
              break;
            }
          case Tag.CHUID_DUNS:
            {
              baos.write(child_tlv.getBytes());
              if (debug) {
                System.out.println("Decoded CHUID_DUNS.");
              }
              break;
            }
          case Tag.CHUID_GUID:
            {
              baos.write(child_tlv.getBytes());
              if (debug) {
                System.out.println("Decoded CHUID_GUID.");
              }
              break;
            }
          case Tag.CHUID_EXPIRATION_DATE:
            {
              baos.write(child_tlv.getBytes());
              if (debug) {
                System.out.println("Decoded CHUID_EXPIRATION_DATE.");
              }
              break;
            }
          case Tag.CHUID_ERROR_DETECT_CODE:
            {
              baos.write(child_tlv.getBytes());
              if (debug) {
                System.out.println("Decoded CHUID_ERROR_DETECT_CODE.");
              }
              break;
            }
          case Tag.CHUID_SIGNATURE:
            {
              // Do nothing with this data
              if (debug) {
                System.out.println("Excluding the asymmetric signature field");
              }
              break;
            }
          default:
            {
              // Everything else, even if not defined
              if (debug) {
                System.out.println(
                    "Including Unknown TLV: " + DataUtil.byteArrayToString(child_tlv.getBytes()));
              }
              baos.write(child_tlv.getBytes());
              break;
            }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return baos.toByteArray();
  }