/** * 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; } } } } }
public void encode() { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); TLV _algorithmID = BERTLVFactory.encodeTLV(new Tag(Tag.AK_ALGORITHM_ID), new byte[] {this.algorithmID}); baos.write(_algorithmID.getBytes()); TLV _parameter = BERTLVFactory.encodeTLV(new Tag(Tag.AK_PARAMETER), this.parameter); baos.write(_parameter.getBytes()); TLV ak_templ = BERTLVFactory.encodeTLV(new Tag(Tag.AK_OBJECT), baos.toByteArray()); this.templ = ak_templ.getBytes(); } catch (Throwable e) { e.printStackTrace(); } }
/** * 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; } } } }
private void encode() { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); // FASC-N TLV _ftlv = BERTLVFactory.encodeTLV(new Tag(Tag.CHUID_FASCN), this.fascn); baos.write(_ftlv.getBytes()); // Agency Code if (this.ac != null) { TLV _actlv = BERTLVFactory.encodeTLV(new Tag(Tag.CHUID_AGENCY_CODE), this.ac); baos.write(_actlv.getBytes()); } // Organizational Identifier if (this.oi != null) { TLV _oitlv = BERTLVFactory.encodeTLV(new Tag(Tag.CHUID_ORG_ID), this.oi); baos.write(_oitlv.getBytes()); } // DUNS if (this.duns != null) { TLV _dunstlv = BERTLVFactory.encodeTLV(new Tag(Tag.CHUID_DUNS), this.duns); baos.write(_dunstlv.getBytes()); } // GUID TLV _guidtlv = BERTLVFactory.encodeTLV(new Tag(Tag.CHUID_GUID), this.guid); baos.write(_guidtlv.getBytes()); // Expiration Date TLV _extlv = BERTLVFactory.encodeTLV(new Tag(Tag.CHUID_EXPIRATION_DATE), this.expires); baos.write(_extlv.getBytes()); // Signature TLV _sigtlv = BERTLVFactory.encodeTLV(new Tag(Tag.CHUID_SIGNATURE), this.signature); baos.write(_sigtlv.getBytes()); // Error Detect Code (Tag only, zero length) TLV _edctlv = BERTLVFactory.encodeTLV(new Tag(Tag.CHUID_ERROR_DETECT_CODE), null); baos.write(_edctlv.getBytes()); this.chuid = baos.toByteArray(); } catch (Throwable e) { e.printStackTrace(); } }
/** * 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(); }